We study the Josephson coupling energy, E-J, between two superconductors (SCs) through magnetic layers, i.e., ferromagnetic metal (FM) and antiferromagnetic insulator (AFI). By the tunneling Hamiltonian approach, analytical formulae of E-J are given in the fourth order perturbation theory as to the tunneling matrix element. In the former case, the E-J exhibits a damped oscillatory dependence on the thickness of the FM and shows a transition between the 0- and the pi-Josephson couplings. In the latter case, the magnetic exchange interaction in the AFI plane suppresses the pi-Josephson coupling, and the 0-Josephson coupling leads to coexistence between SC and AFI. It is found that the origin of pi-Josephson coupling in the SC/AFI/SC junction is different from that in the SC/FM/SC one. (C) 2007 Elsevier B.V. All rights reserved.