The present study investigates the electronic structure, magnetic properties, and optical performance of anatase TiO2 and pure TiO2 systems with the addition of rare earth elements RE (Eu/Gd/Lu). Using first-principles calculations based on density-functional theory, we explore the effects of RE doping on these systems. Our calculations reveal that the structural stability remains intact under the conditions of RE doping. The total magnetic moment is determined to be 2.987 μB, 6.052 μB, and 0 μB for Eu, Gd, and Lu-doped TiO2 respectively. Furthermore, the band gap of Eu/Gd/Lu-doped TiO2 decreases significantly to 1.91eV, 1.8eV, and 1.88eV, leading to a lower energy requirement for electron transition, as compared to the initial energy band gap of 2.31eV. The incorporation of rare earth elements also results in an increase in the number of valence and conduction band energy levels near the Fermi level, primarily influenced by orbital electrons in the 4f layer of the rare earth elements. Additionally, our findings demonstrate a remarkable shift towards the red region in the absorption spectrum of the Eu-TiO2 system, accompanied by a relatively long photocarrier lifetime. These characteristics suggest its potential as a photocatalyst with enhanced performance. Overall, this research provides valuable theoretical insights towards the development and synthesis of novel TiO2 photocatalysts.