In order to achieve energy savings and promote on-site integration of photovoltaic energy in electrified railways, a topology structure is proposed for the integration of photovoltaic (PV) and the energy storage system (ESS) into the traction power supply system (TPSS) based on a railway power conditioner (RPC). This paper analyzes the composition and operation principles of this structure. To assess the economic benefits brought by the integration of photovoltaic and energy storage systems, a bilevel optimization model is established, with the objectives of optimizing energy storage capacity configuration and photovoltaic energy integration. The KKT (Karush–Kuhn–Tucker) method is employed to transform the model into a single-layer mixed-integer linear programming model, which is then solved using the CPLEX solver in MATLAB. The research findings indicate that, with the configuration of the ESS, the optimal PV consumption rate achieved is 96.8749%. Compared to a 100% PV consumption rate, the ESS capacity configuration is reduced by 13.14%, and the overall operational cost of the TPSS is at its lowest. The study suggests that the proposed bilevel optimization algorithm can more effectively consider PV consumption, leading to enhanced economic performance of the TPSS operation.