First-principles calculations have been carried out to investigate the possibility of B-, N-, Si-, and S-doped black phosphorus carbide monolayers (B-, N-, Si-, and S-bPCs) as efficient gas sensors to detect and eliminate toxic gas molecules such as NO2 and NH3. The influence of O2 and H2O has also been considered. It is found that O2, H2O, NO2, and NH3 are all physisorbed on N- and S-bPCs. Nevertheless, the moderate adsorption energy and large charge transfer of NO2 on N-bPC indicate that N-bPC is more suitable to detect NO2. The chemisorption is observed when NO2 and NH3 are adsorbed on B-bPC, and O2, NO2, and NH3 on Si-bPC, by which highly enhanced sensitivity toward these molecules can be realized. Due to the strong adsorption, B- and Si-bPCs can be used to detect and filter NO2 and NH3 at different working temperatures. The work function has been calculated to further interpret the adsorption mechanism. It increases with B and Si dopants and decreases with N and S dopants. The adsorption of molecules leads to different variations of the work function, which is correlated with the direction of charge transfer. Our theoretical investigations help us better understand the mechanism of bPC as a NO2 and NH3 gas sensor and provide a facile method to broaden its application in industrial, medical, and environmental monitoring.