Scientists and researchers have made numerous efforts to reduce global carbon emissions. One of the greatest methods to reach this goal is using renewable energies, especially benefiting from biomass, because of their higher efficiency and lower GHG emissions. In this regard, this paper represents a fuel cell based on biogas fuel, in which the city sludge is initially treated and then fed to a digester. The gas is cleaned and put into the fuel cell for power generation and heating. The system has superiority over other biogas-fed SOFC schemes over its better installment of subsystems. The system is analyzed from technical and environmental aspects, and parametric sensitivity is carried out. Also, cooling is generated from the waste heat to minimize the effects of environmental pollution. It is exhibited that fuel utilization factor, stack temperature, and gas composition seriously affect system performance. Finally, the optimization is conducted, and the best solution point is found with an effectiveness of 56.2%, emission of 0.021 kg/kWh, and a cost of 0.05472 $/kWh.