Exploring inexpensive and efficient bifunctional electrocatalysts for oxygen reduction reaction (ORR) and oxygen evolution reaction (OER) is critical for rechargeable metal-air batteries. Herein, we report a new 3D hierarchical sulfur and nitrogen co-doped carbon nanocages (hSNCNC) as a promising bifunctional oxygen electrocatalyst by an in-situ MgO template method with pyridine and thiophene as the mixed precursor. The as-prepared hSNCNC exhibits a positive half-wave potential of 0.792 V (vs. reversible hydrogen electrode, RHE) for ORR, and a low operating potential of 1.640 V at a 10 mA cm−2 current density for OER. The reversible oxygen electrode index is 0.847 V, far superior to commercial Pt/C and IrO2, which reaches the top level of the reported bifunctional catalysts. Consequently, the hSNCNC as air cathodes in an assembled Zn-air battery features low charge/discharge overpotential and long lifetime. The remarkable properties arises from the introduced multiple heteroatom dopants and stable 3D hierarchical structure with multi-scale pores, which provides the abundant uniform high-active S and N species and efficient charge transfer as well as mass transportation. These results demonstrate the potential strategy in developing suitable carbon-based bi-/multi-functional catalysts to enable the next generation of the rechargeable metal-air batteries.