The development of highly active and easily coupled non-noble metal electrocatalysts for oxygen evolution reaction (OER) and hydrogen evolution reaction (HER) is of great significance for the H2 production by water electrolysis. Here, we have shown an anion-modulated HER and OER activity of 1D Co-Mo based interstitial compound heterojunctions for effective overall water splitting. The Co-Mo based complex nanowires from a one-pot route with high yields can be converted into MoC-Co heterojunction nanowires under N2 atmosphere, while a pyrolysis under NH3 can give CoMoN-CoN heterostructures. The work function revealed Mott-Schottky effect between interfaces of two heterostructures, which can introduce electron redistribution and thus promote the HER/OER process. The MoC-Co heterojunction nanowires delivers good HER activity at a low overpotential of 39 mV to afford a current density of 10 mA/cm2. Density functional theory calculations show that the heterogeneous interface formed between the Co and MoC optimizes the hydrogen adsorption free energy. Concurrently, CoMoN-CoN heterojunction nanowires exhibits good OER performance with a low overpotential of 260 mV to reach 10 mA/cm2, being superior to RuO2. The two catalysts can be coupled to assemble a two-electrode cell with a solar-to-hydrogen efficiency of 12.3% at 1.54 V. This work provides an effective means to design easily coupled HER and OER catalysts for H2 production by water electrolysis.