Using maximally localized Wannier functions obtained from DFT calculations, we derive an effective Hubbard Hamiltonian for a bilayer of Sr$_3$Cr$_2$O$_7$, the $n=2$ member of the Ruddlesden-Popper Sr$_{n+1}$Cr$_n$O$_{3n+1}$ system. The model consists of effective $t_{2g}$ orbitals of Cr in two square lattices, one above the other. The model is further reduced at low energies and two electrons per site, to an effective Kugel-Khomskii Hamiltonian that describes interacting spins 1 and pseudospins 1/2 at each site describing spin and orbitals degrees of freedom respectively. We solve this Hamiltonian at zero temperature using pseudospin bond operators and spin waves. Our results confirm a previous experimental and theoretical study that proposes spin ordering antiferromagnetic in the planes and ferromagnetic between planes, while pseudospins form vertical singlets, although the interplane separation is larger than the nearest-neighbor distance in the plane. We explain the physics behind this rather unexpected behavior.