This paper is concerned with analysis of electromagnetic wave scattering by an obstacle which is embedded in a two-layered lossy medium separated by an unbounded rough surface. Given a dipole point source, the direct problem is to determine the electromagnetic wave field for the given obstacle and unbounded rough surface; the inverse problem is to reconstruct simultaneously the obstacle and unbounded rough surface from the electromagnetic field measured on a plane surface above the obstacle. For the direct problem, a new boundary integral equation is proposed and its well-posedness is established. The analysis is based on the exponential decay of the dyadic Green function for Maxwell's equations in a lossy medium. For the inverse problem, the global uniqueness is proved and a local stability is discussed. A crucial step in the proof of the stability is to obtain the existence and characterization of the domain derivative of the electric field with respect to the shape of the obstacle and unbounded rough surface. , J j denote the electric field, the magnetic field, the electric current density, respectively, and ρ j = (iω) −1 ∇ · J j is the electric charge density. The external current source is assumed to be located in Ω 1 . The relation between the electric current density and the electric field is given bywhere J cs stands for the current source.