Role of trivalent Sr substituents and Sr vacancies in tetragonal and polar states of SrTiO3