The electrocatalytic nitrite/nitrate reduction reaction (eNO2RR/eNO3RR) offer a promising route for green ammonia production. The development of low cost, highly selective and long-lasting electrocatalysts for eNO2RR/eNO3RR is challenging. Herein, a method is presented for constructing Cu3P-Fe2P heterostructures on iron foam (CuFe-P/IF) that facilitates the effective conversion of NO2 - and NO3 - to NH3. At -0.1 and -0.2V versus RHE (reversible hydrogen electrode), CuFe-P/IF achieves a Faradaic efficiency (FE) for NH3 production of 98.36% for eNO2RR and 72% for eNO3RR, while also demonstrating considerable stability across numerous cycles. The superior performance of CuFe-P/IF catalyst is due tothe rich Cu3P-Fe2P heterstuctures. Density functional theory calculations have shed light on the distinct roles that Cu3P and Fe2P play at different stages of the eNO2RR/eNO3RR processes. Fe2P is notably active in the early stages, engaging in the capture of NO2 -/NO3 -, O─H formation, and N─OH scission. Conversely, Cu3P becomes more dominant in the subsequent steps, which involve the formation of N─H bonds, elimination of OH* species, and desorption of the final products. Finally, a primary Zn-NO2 - battery is assembled using CuFe-P/IF as the cathode catalyst, which exhibits a power density of 4.34mW cm-2 and an impressive NH3 FE of 96.59%.