The electronic structures and optical properties of boron/phosphorus mono- and co-doped β silicon nitride are studied by the first-principles plane-wave ultrasoft pseudopotential method with the generalized gradient approximation. The results are obtained as follows. The B-doped system has a better stability than the P-doped system, while the P-doped structure has a stronger ionicity. The mono-doping and co-doping can narrow the band gap of β silicon nitride while the co-doping introduces the deep impurity levels and strengthens the localized states. The mono-doping causes the imaginary part of dielectric function, the peaks of absorption spectra and energy loss spectra to red-shift, and their amplitudes to decrease, resulting in a significant difference from the intrinsic state. The co-doping induces the peak of imaginary part of the dielectric function to blue-shift, broadens the energy loss peak, greatly enhances the electronic transition in the high energy region, and controlling the ratio of the numbers of atoms (B and P) in co-doping can achieve a low charged defect concentration, implying its potential application in the field of microelectronics.