The combined effect of both nonmagnetic and magnetic impurities on the superconducting transition temperature is studied theoretically within the BCS model. An expression for the critical temperature as a function of potential and spin-flip scattering rates is derived for a two-dimensional superconductor with arbitrary in-plane anisotropy of the superconducting order parameter, ranging from isotropic s-wave to d-wave (or any pairing state with nonzero angular momentum) and including anisotropic s-wave and mixed (d+s)-wave as particular cases. This expression generalizes the well-known Abrikosov-Gor'kov formula for the critical temperature of impure superconductors. The effect of defects and impurities in high temperature superconductors is discussed.