All diesel-only trains in the UK will be phased out by 2040. Hydrogen and ammonia emerge as alternative zero-carbon fuel for greener railway. Solid Oxide Fuel Cells (SOFCs) provide an alternative prime mover option, which efficiently convert zero-carbon fuels into electricity without emitting nitrogen oxides (NOx), unlike traditional engines. Superior to Proton Exchange Membrane Fuel Cells (PEMFCs) in efficiency, SOFCs fulfil MW-scale power needs and can use ammonia directly. This study investigates innovative strategies for integrating SOFCs into hybrid rail powertrains using hydrogen or ammonia. Utilizing an optimization framework incorporating Particle Swarm Optimization (PSO), the study aims to minimize operational costs while considering capital and replacement expenditures, powertrain performance, and component sizing. The findings suggest that hybrid powertrains based on ammonia-fueled SOFCs may potentially reduce costs by 30% compared to their hydrogen counterparts, albeit requiring additional space for engine compartments. Ammonia-fueled SOFCs trains also exhibit a 5% higher efficiency at End-of-Life (EoL), showing less performance degradation than those powered by hydrogen. The State of Charge (SoC) of the batteries in range of 30–70% for both cases is identified as most cost-effective.