hbox {TiO}_2 and hbox {SrTiO}_3 are well known materials in the field of photocatalysis due to their exceptional electronic structure, high chemical stability, non-toxicity and low cost. However, owing to the wide band gap, these can be utilized only in the UV region. Thus, it’s necessary to expand their optical response in visible region by reducing their band gap through doping with metals, nonmetals or the combination of different elements, while retaining intact the photocatalytic efficiency. We report here, the codoping of a metal and a nonmetal in anatase hbox {TiO}_2 and hbox {SrTiO}_3 for efficient photocatalytic water splitting using hybrid density functional theory and ab initio atomistic thermodynamics. The latter ensures to capture the environmental effect to understand thermodynamic stability of the charged defects at a realistic condition. We have observed that the charged defects are stable in addition to neutral defects in anatase hbox {TiO}_2 and the codopants act as donor as well as acceptor depending on the nature of doping (p-type or n-type). However, the most stable codopants in hbox {SrTiO}_3 mostly act as donor. Our results reveal that despite the response in visible light region, the codoping in hbox {TiO}_2 and hbox {SrTiO}_3 cannot always enhance the photocatalytic activity due to either the formation of recombination centers or the large shift in the conduction band minimum or valence band maximum. Amongst various metal-nonmetal combinations, hbox {Mn}_text {Ti}hbox {S}_text {O} (i.e. Mn is substituted at Ti site and S is substituted at O site), hbox {S}_text {O} in anatase hbox {TiO}_2 and hbox {Mn}_text {Ti}hbox {S}_text {O}, hbox {Mn}_text {Sr}hbox {N}_text {O} in hbox {SrTiO}_3 are the most potent candidates to enhance the photocatalytic efficiency of anatase hbox {TiO}_2 and hbox {SrTiO}_3 under visible light irradiation.