A comprehensive theory of shallow impurities in quantum wells (QW's) is presented. The energy levels of donor and acceptor impurities are calculated within the effective mass theory including the mismatch of the band parameters and of the dielectric constants between well and barrier materials. The theory also accounts for Coulomb coupling between different subbands and, in the case of acceptors, for valence-band mixing. The method is based on an expansion of the envelope functions into a basis set consisting of products of two-dimensional hydrogenic-like functions and impurity-free QW eigen-functions at k parallel-to = 0. The present method is suited for the ground as well as for the excited impurity states and thus enables us to obtain the oscillator strengths of infrared transitions between these states. The results show a good agreement with recent experiments on both donor and acceptor impurities.