Transitioning from fossil fuels to clean energy sources is vital for carbon neutrality and sustainable development. This study evaluates the integration of photovoltaic (PV) technology into China’s extensive railway network and reveals that suitable areas on rails could potentially generate 204.6 TWh of electricity annually, equivalent to more than twice of the Three Gorges Power Station’s output, and accounting for approximately 9.2% of China’s total renewable electricity generation in 2020 (2,214.8 TWh). The proposed hybrid railway PV energy system is estimated at a national average levelized cost of electricity of 0.14 CNY kWh−1, with a potential profit of CNY 77.8 billion upon transitioning from the current electricity supply. Among 371 cities analyzed, 291 (78.4%) are expected to reach a production-side grid parity, while all cities would achieve user-side grid parity. The implementation of this PV system could significantly mitigate environmental impacts, reducing carbon emissions by 126.5 Mt and lowering air pollutants, including 64 199 tons of NOX, 44 423 tons of SO2, and 7789 tons of PMX. Substantial railways in rural regions can optimize the energy consumption structure of rural residents, reducing the share of coal and liquefied petroleum gas in per capita energy consumption from 29.44% to 7.27%, and leading their average annual expenditure on primary energy sources dropping from CNY667.9 to CNY502.7—a 24.23% reduction.