Generalized eikonal approximation. 2. Propagation of stationary electromagnetic waves in linear and nonlinear media