Power outages of the electricity grid threaten the proper operation of critical infrastructure such as hospitals. To cope with this problem, emergency diesel generators (DGs) are often used to guarantee continuous and resilient electricity supply, resulting in increased costs and greenhouse gas (GHG) emissions. Thus, this study aims to investigate the economic feasibility of both reducing and replacing emergency diesel generators with solar photovoltaic (PV) systems, battery energy storage systems (BESS) and demand-side management. A mixed-integer quadratically constrained program is used to find the optimal configuration in terms of capacities of new assets, as well as the optimal scheduling of both BESS and flexible loads, that minimises the levelised cost of energy (LCOE). The model is applied to an existing hospital and its surrounding community located in Gulu, Uganda. The results show that full replacement of the DGs will require an additional 500 kWp of PV and 1591 kWh of BESS. This new configuration will decrease LCOE by 26% compared to the actual situation, with a simple payback time of 6.2 years and a reduction of 74% in GHG emissions.