The electronic properties, including bandgap and conductivity, are critical for nearly all applications of multifunctional perovskite oxide ferroelectrics. Here we analysed possibility to induce semiconductor behaviour in these materials, which are basically insulators, by replacement of several percent of oxygen atoms with nitrogen, hydrogen, or vacancies. We explored this approach for one of the best studied members of the large family of ABO3 perovskite ferroelectrics — strontium titanate (SrTiO3). The atomic and electronic structure of defects were theoretically investigated using the large-scale first-principles calculations for both bulk crystal and thin films. The results of calculations were experimentally verified by studies of the optical properties at photon energies from 25 meV to 8.8 eV for in-situ prepared thin films. It was demonstrated that substitutions and vacancies prefer locations at surfaces or phase boundaries over those inside crystallites. At the same time, local states in the bandgap can be produced by vacancies located both inside the crystals and at the surface, but by nitrogen substitution only inside crystals. Wide-bandgap insulator phases were evidenced for all defects. Compared to pure SrTiO3 films, bandgap widening due to defects was theoretically predicted and experimentally detected.