The Green function method in the theory of nuclear and electron spin polarization. I. General theory, zero approximation and applications