Enhancing active states on the catalyst surface by modulating the adsorption-desorption properties of reactant species is crucial to optimizing the electrocatalytic activity of transition metal-based nanostructured materials. In this work, an efficient optimization strategy is proposed by co-modulating the dual anions (C and S) in Ni3C/Ni3S2, the heterostructured electrocatalyst, which is prepared via a simple hot-injection method. The presence of Ni3C/Ni3S2 heterojunctions accelerates the charge carrier transfer and promotes the generation of active sites, enabling the heterostructured electrocatalyst to achieve current densities of 10/100mA cm-2 at 1.37V/1.53V. The Faradaic efficiencies for formate production coupled with hydrogen evolution approach 100%, accompanied with a stability record of 350h. Additionally, operando electrochemical impedance spectroscopy (EIS), in situ Raman spectroscopy, and density functional theory (DFT) calculations further demonstrate that the creation of Ni3C/Ni3S2 heterointerfaces originating from dual anions' (C and S) differentiation is effective in adjusting the d-band center of active Ni atoms, promoting the generation of active sites, as well as optimizing the adsorption and desorption of reaction intermediates. This dual anions co-modulation strategy to stable heterostructure provides a general route for constructing high-performance transition metal-based electrocatalysts.