1. Introduction
Decarbonization stands as one of the greatest global challenges of the 21st century, driven by the sharp rise in carbon dioxide emissions, which have increased by 109% since 1975 [
1], and by international commitments such as the Paris Agreement, which seeks to limit the rise in global average temperature to 1.5 °C by 2050 [
2]. One particularly promising strategy to achieve this goal is the local production of hydrogen using renewable energy sources, such as solar or wind power. This approach enables the generation of renewable hydrogen with low or even zero CO
2 emissions [
3], while also mitigating the energy losses typically associated with transmission in centralized systems. In addition, the use of hydrogen as an energy vector contributes to the reduction of local air pollution, a particularly relevant benefit considering that 90% of EU countries currently exceed the air quality limits set by the World Health Organization, with serious consequences for public health [
4].
Given the potential of hydrogen as a clean energy carrier, integrating it into decentralized systems becomes increasingly relevant. In this context, microgrids emerge as an ideal platform for coupling renewable hydrogen technologies with local energy management.
Microgrids (MGs) are autonomous power networks that can generate, store, and deliver electricity locally, all while coordinating with the main grid. Both emerging and industrialized regions are paying increasing attention to MGs, since they enhance resilience in areas with fragile infrastructure or high energy costs. By transferring asset management and operational decisions from central utilities to local actors, MGs disrupt the conventional top-down model and open a route to more democratic, adaptable, and sustainable energy systems [
5]. Integrated control over generation and storage enables MGs to withstand grid disturbances, ease peak stress on network assets, and deliver ancillary functions such as black-start capability and frequency regulation. Such features make MGs a key element of the broader move toward smart grids, in which distributed resources and digital optimization supersede large central generation as the organizing principle [
6].
Optimization plays a central role in the design and operation of microgrid systems, enabling the efficient coordination of renewable sources, storage technologies, and energy transactions with the main grid. Typically, these problems are formulated to balance economy, reliability, and sustainability under the uncertainty of renewable generation and load. Two main families of approaches are prevalent. On the one hand, mathematical programming methods, particularly mixed-integer linear programming (MILP), are widely applied to schedule resources and minimize operating costs. Recent studies have demonstrated their effectiveness in real-world contexts [
7,
8,
9,
10,
11,
12]. In [
9], an MILP model is modeled to size a solar–wind hybrid system for the winemaking sector, demonstrating significant savings and reduced dependence on the power grid over a 25-year horizon. In [
10], the MILP optimization model applied to optimize hybrid renewable configurations reported reductions of more than 60% in energy costs over 20 years. On the other hand, metaheuristic approaches—including genetic algorithms (GA), particle swarm optimization (PSO), differential evolution (DE) and their hybrids—are increasingly adopted to address large-scale, non-linear, and highly constrained formulations, where deterministic methods face computational limitations [
13,
14,
15,
16,
17].
Portugal provides a notable national example. Between 1 January and 31 May 2025, renewables supplied roughly 81% of Portugal’s electricity, thanks to its longstanding hydro fleet, mature onshore wind, and rapidly growing photovoltaic parks [
18]. The Portuguese National Energy and Climate Plan 2030 (PNEC 2030) fixes clear goals: renewables should cover 51% of gross final energy use and 96% of electricity generation by 2030 [
19]. Realizing these targets demands heavy investment in flexibility assets—batteries, green hydrogen, and demand-side management—alongside policies that foster self-consumption and community energy initiatives. Within this context, microgrids emerge as appealing platforms for absorbing significant variable generation while benefiting local consumers, the broader grid, and the climate.
Although hydrogen is the universe’s most abundant element and appears on Earth only in compounds, it is gaining significant attention as a flexible energy carrier. With a gravimetric energy density far exceeding that of fossil fuels, hydrogen used in fuel cells or clean combustion produces only water as a direct by-product [
20]. These traits suit hydrogen to long-duration energy storage, decarbonizing industrial feedstocks, and enabling low-carbon mobility.
Recent strategy papers underscore this role. At the European scale, the REPowerEU plan adopted in 2022 set a goal to generate 10 Mt of renewable hydrogen inside the EU and import another 10 Mt by 2030 [
21]. Portugal’s PNEC 2030 reflects these ambitions by targeting 2.5 GW of domestic electrolysis capacity by 2030 and an initial 5% hydrogen blend in the natural-gas system [
19]. In addition, the Recovery and Resilience Plan allocates €185 million to launch early projects and position the Sines Industrial Hub as a hydrogen-industry flagship [
22].
A color-based nomenclature is commonly used to indicate production pathways and their life-cycle emissions.
Grey hydrogen is chiefly obtained via steam-methane reforming, a well-established and inexpensive method that releases 8.5–12 kg CO
2 per kilogram of hydrogen [
23,
24,
25]. It still represented about 60% of world production in 2023 [
26]. Blue hydrogen adds carbon capture, utilization and storage to the same reforming process, cutting emissions relative to grey hydrogen; however, residual carbon and capture costs prevent full climate neutrality [
27]. Green hydrogen comes from water electrolysis driven solely by renewable electricity. As the method emits no direct carbon, it holds significant promise for deep decarbonization [
23]. Yet in 2023 green hydrogen made up under 1% of the 97 million t global output, chiefly because of high capital and electricity costs [
26]. Even so, research activity is rising swiftly, indicating faster learning curves and growing commercial interest.
Although additional labels such as turquoise, pink, brown, black, and golden are used, grey, blue, and green dominate discussions [
28,
29,
30].
Electrolyzers produce hydrogen and oxygen from water by driving an electric current through an electrolyte [
31]. Four principal designs shape current research and commercial deployment.
Alkaline water electrolyzers (AWEs) operate with a liquid potassium- or sodium-hydroxide electrolyte at moderate temperatures. The technology is mature, comparatively cheap, and can last nearly 90,000 h, but it offers only moderate efficiency and limited dynamic response [
32,
33]. Proton-exchange membrane electrolyzers (PEMEs) rely on a solid polymer membrane, achieve high current densities, and track load rapidly, supplying hydrogen at 99.99% purity or better. Although noble-metal catalysts like platinum and iridium elevate capex, PEME units reach 70–80% efficiency and occupy less space than AWEs [
34]. Under standard conditions (25 °C, 1 bar), the theoretical minimum energy required for water electrolysis is 32.9 kWh/kg H
2, with 100% efficiency defined by the HHV of 39.4 kWh/kg [
35]. Anion-exchange membrane electrolyzers (AEMEs) seek to blend the low catalyst expense of alkaline systems with the compactness of membrane cells. They use non-noble metals, yet membrane stability and ionic conductivity remain below commercial benchmarks, keeping the technology at the demonstration stage [
36,
37]. Solid-oxide electrolysis cells (SOECs) run at 500–1000 °C; providing part of the input energy as heat lifts efficiency up to 85% and cuts specific electricity usage, but creates challenges in sealing, materials durability, and cycling. As a result, SOECs is still mainly limited to labs and early pilots [
38].
Fuel cells (FCs) generate electricity from hydrogen or hydrogen-rich fuels via electrochemical reactions whose by-products are water and heat with minimal pollutants [
20]. Operating temperatures, electrolytes, and performance profiles vary widely, allowing different FC types to suit specific microgrid roles [
39].
Direct methanol fuel cells (DMFCs) function at low temperatures with liquid methanol, which favors portable uses, yet efficiency is moderate because of fuel crossover [
40]. Alkaline fuel cells (AFCs) deliver high electrical efficiency but are vulnerable to carbon-dioxide contamination, restricting deployment to controlled environments [
39]. Phosphoric-acid fuel cells (PAFCs) operate at intermediate temperatures, accept reformate fuels, and therefore fit combined heat-and-power installations in small to medium buildings [
39]. Molten-carbonate fuel cells (MCFCs) provide fuel flexibility and sound electrical efficiency at 600 °C, yet deal with material corrosion and relatively low power density [
39]. Solid-oxide fuel cells (SOFCs) work at the highest temperatures, achieve electrical efficiencies up to 60%, and allow internal fuel reforming. They are viewed as promising for microgrid baseload supply and for coupling with electrolysis in reversible solid-oxide systems [
41]. Proton-exchange membrane fuel cells (PEMFCs) feature rapid start-up, high power density, and zero local emissions when supplied with green hydrogen. They have reached commercial status in transport and stationary backup applications, although catalyst expense and membrane longevity still pose challenges [
42,
43]. The theoretical maximum output of a PEM fuel cell is 32.7 kWh/kg H
2, corresponding to 83% efficiency based on the HHV under standard conditions [
44,
45].
A relevant line of research has demonstrated the importance of integrating the life cycle perspective into the development of energy management strategies for hybrid systems. In [
46], a health-aware energy management system for fuel cells and batteries is proposed, with the aim of simultaneously minimizing hydrogen consumption and component degradation. The results revealed a 64.68% reduction in total costs compared to conventional control, mainly due to less degradation from inactivity and load variations in the stacks. This work shows that optimization models should consider not only short-term efficiency, but also the long-term sustainability and reliability of hydrogen-based systems.
Comparing the two technologies allows us to better contextualize the role of hydrogen in energy storage. Batteries offer high energy efficiency and competitive costs, making them a mature solution for short-term storage. However, they face limitations associated with degradation after multiple cycles and the intensive extraction of critical metals, with significant environmental impacts. Hydrogen, despite its lower efficiency (considering electrolysis, storage, and conversion into fuel cells), stands out for its medium and long-term storage capacity and its integration on a larger scale into microgrids. A life cycle perspective also shows that both technologies involve different environmental trade-offs: in batteries, the impacts are mainly concentrated in the production and recycling phase, while in hydrogen they are distributed throughout the entire cycle [
47]. Thus, the choice between technologies should not be based solely on immediate efficiency, but also on criteria of flexibility, scalability, and long-term sustainability.
In this work, a mathematical model was developed to manage a hydrogen storage system powered by surplus renewable energy. The proposed approach aims to optimize system performance by simulating various operational scenarios, considering consumption profiles, the variability of renewable energy generation, and the interconnection with the electrical grid. The analysis is structured around three main objectives: firstly, to minimize operating costs; secondly, to contribute to grid stability; and thirdly, to maximize the utilization of surplus energy.
This work contributes directly to the United Nations Sustainable Development Goals (SDGs), specifically SDG 7 (Affordable and Clean Energy), by promoting renewable energy use and hydrogen-based storage; SDG 9 (Industry, Innovation and Infrastructure), by proposing innovative technological solutions for energy management in microgrids; and SDG 11 (Sustainable Cities and Communities), by supporting the development of more resilient, autonomous, and low-carbon urban systems [
48].
This paper is organized as follows.
Section 1 introduces the theme and provides a review of the literature.
Section 2 presents a description of the proposed energy system.
Section 3 presents the optimization model for the optimal sizing of the hybrid system and the optimal energy exchanges.
Section 4 presents the case studies, complemented by the technical characterization of the components, and
Section 5 is dedicated to the analysis of the results. Finally,
Section 6 presents the main conclusions of the work and points to directions for future work.
3. Optimization Model
The mathematical model developed in this work aims to optimize the energy production of a microgrid that integrates photovoltaic generation, hydrogen production and storage, and a fuel cell system. The formulation seeks to minimize operating costs while ensuring the reliability and sustainability of the system. The optimization approach is formulated as a mixed-integer linear programming (MILP) problem, allowing the definition of an optimal scheduling of energy flows: from renewable production, through electrical conversion to hydrogen via the electrolyzer, storage in a pressurized tank, and subsequent reconversion into electricity through the fuel cell. In addition, the model considers energy import and export flows with the grid, ensuring flexibility and security of supply. Four typical days are used, one for each season. Each day is subdivided into 24 hourly intervals of demand, renewable production, and electricity prices. Each day is replicated according to the number of days in the respective season, enabling analysis of the system’s energy flows throughout the year.
The sets, parameters, and decision variables employed in the model are summarized in
Table 1,
Table 2, and
Table 3, respectively.
The objective function (
1) minimizes the net annual expenditure on electricity costs, which is defined as the total cost of electricity purchased from the grid minus the revenue from electricity sales.
In Constraint (
2), for every hour
, the sum of electricity sources (PV generation, grid imports, and fuel-cell output) must equal the sum of electricity sinks (load demand, electrolyzer consumption, and any power exported to the grid).
Constraint (
3) ensures that the electrolyzer’s electricity consumption at any time step
t does not exceed its rated maximum capacity
.
Constraint (
4) limits the fuel-cell’s electrical output at its rated maximum
.
Constraint (
5) sets the hydrogen inventory in the first hour of the year. At the beginning of the simulation, the hydrogen level is initialized with the starting stock
. The net balance at the first time step accounts for the hydrogen produced
and consumed
.
Constraint (
6) updates the hydrogen storage level for each time step
. The balance is computed by carrying over the previous level, adding the hydrogen produced, and subtracting the hydrogen consumed.
Constraint (
7) ensures the model never consumes more hydrogen than was available at the end of the previous hour.
Constraint (
8) limits the hydrogen stock to the maximum storage capacity
.
Constraints (
9) and (
10) establish the logical relationship between grid imports to the binary variable
. Specifically, when
, Constraint (
9) forces
to zero, preventing electricity imports. Conversely, when
, Constraint (
10) ensures that the grid purchase is strictly positive (at least
), while Constraint (
9) sets an upper bound through the
parameter. Together, these constraints guarantee consistency between the binary activation variable and the continuous flow decision.
Constraints (
11) and (
12) link grid exports to the binary variable
. When
, they force
to zero, preventing electricity sales. When
, they restrict the export flow to lie between the minimum threshold
and the upper bound
.
Constraint (
13) avoids simultaneous buying and selling of electricity with the grid in the same time step. The binary variables
and
ensure mutually exclusive decisions: if electricity is being purchased from the grid (
), then selling is not allowed (
), and vice versa.
Constraints (
14) and (
15) link the electrolyzer’s power draw to its binary status
, ensuring it is zero when the unit is off and between a minimum threshold
and the upper bound
when on.
Constraints (
16) and (
17) link the fuel-cell output to its binary status
.
Constraint (
18) guarantees that the electrolyzer and the fuel cell do not operate simultaneously within the same time period. Since the electrolyzer consumes electricity to produce hydrogen and the fuel cell consumes hydrogen to generate electricity, running both devices at the same time would be energetically inefficient. By enforcing exclusivity through the binary variables
and
, the model ensures operational coherence and avoids unnecessary cycling between the two technologies.
Constraints (
19) guarantees that all energy and hydrogen-related decision variables remain physically meaningful. Negative values for purchases, sales, power usage, or tank levels are not allowed.
Constraints (
20) specify the binary domain of the decision variables representing the on/off operational states of the electrolyser, fuel cell, and grid interactions.
5. Results and Discussion
The main aim of this study is to analyze the technical and economic feasibility of a microgrid equipped with a hydrogen storage system. This system uses surplus energy from renewable sources and, when economically advantageous, purchases energy for subsequent storage in the form of hydrogen. The mathematical optimization model implemented determines all the energy flows in the system, identifying the most economically favorable times for hydrogen production and storage, the optimal conditions for its use (both for internal consumption and for energy sales), as well as the most profitable strategies for buying and selling energy to the grid. The model was solved using FICO Xpress Workbench Optimization software (Xpress Optimizer Version 45.01.01) [
51]. A comparative analysis of the two scenarios will facilitate an assessment of the economic impact of implementing the system, the respective environmental benefits, and the potential for improvement associated with future technological development in this area. Case Study I is based on the actual technical characteristics of equipment currently available on the market. Case Study II is a prospective scenario that assumes theoretically possible efficiency improvements, representing the evolutionary potential of hydrogen technologies.
5.1. Case Study I
Case Study I is based on the actual technical characteristics of equipment currently available on the market. The aim is to understand how the system would behave when operated with real parameters.
Figure 2 shows the hourly distribution of energy consumption in Case Study I for the four seasons of the year. In all seasons, there is a strong dependence on energy purchased from the electricity grid, particularly in the early and late hours of the day, when there is no photovoltaic production. During the daytime, there is greater penetration of solar energy, especially in spring and summer, which allows for a reduction in the use of the grid during these periods.
With regard to the fuel cell (FC), its use is quite limited throughout the year. Only in summer is the FC activated, specifically between 9 p.m. and 11 p.m., when solar production has ceased and energy demand remains high. This behavior is explained by the reduced surplus of renewable energy, which, although sufficient to supply the load for several hours of the day, does not generate a significant surplus for continuous hydrogen production. In this way, the model chooses to store the available hydrogen for use at specific times considered most advantageous from an economic point of view.
Furthermore,
Figure 3 shows that no energy was purchased from the grid for hydrogen production, which is justified by the insufficient efficiency of the system components. Hydrogen is stored only through small surpluses from renewable production.
Figure 4 shows the total energy accumulated throughout the four seasons.
It can be observed in
Figure 4 that total energy consumption is highest in summer and spring, followed by winter and, finally, autumn, with the lowest consumption. This variation may be associated with fluctuations in seasonal thermal or electrical load, such as the use of cooling in summer. Photovoltaic production (EPV) partially follows this variation.
With regard to fuel cells, their use is residual, being recorded only in summer and autumn. This suggests that hydrogen production from renewable surpluses was only possible on an ad hoc basis during these periods.
It is important to note that summer was the only season of the year in which energy was sold. In this season, the model considered it more advantageous to sell the surplus renewable energy rather than use it to produce more hydrogen, as can be seen in
Figure 5. It can also be seen that it is in the summer that the highest consumption of hydrogen through the fuel cell occurs. This is due to the fact that, during the previous seasons, a sufficient amount of hydrogen was stored to power the load at specific times during this season.
5.2. Case Study II
Case Study II uses improved parameters, representing a significant evolution in equipment efficiency. This scenario allows us to see how the system might perform in the future, considering the availability of more efficient equipment.
Figure 6 shows the hourly distribution of energy consumption throughout the four seasons of the year, in Case Study II.
In all seasons, there is intensive use of photovoltaic energy during the daytime. Outside this period, the system uses fuel cells and the electricity grid to meet demand.
The fuel cell plays a key role in all seasonal periods, being activated predominantly at the end of the day (between 6 p.m. and 11 p.m.), when photovoltaic production has ceased and the load remains high. This strategy significantly reduces dependence on the electricity grid. Compared to Case Study I, hydrogen use is much more pronounced, since, with higher efficiencies, it becomes advantageous to purchase energy from the grid for hydrogen production and storage, as can be seen in
Figure 7.
Figure 8 shows the total energy accumulated throughout the year in Case Study II, by season.
It should be noted that no energy was sold, since whenever there was a surplus of renewable production, it was used for hydrogen production. The presence of FC production throughout the year shows that, unlike Case Study I, in Case Study II, the accumulation of hydrogen is considered advantageous, even from energy acquired from the grid.
In
Figure 9, it can be seen that in winter a large amount of hydrogen is produced, which is stored and subsequently consumed throughout the rest of the year.
5.3. Comparative Analysis
In order to highlight the economic impact of integrating the hydrogen system into the microgrid, the monetary savings at the end of one year were calculated.
Table 6 shows the amounts of energy purchased in each case, as well as the respective annual cost associated with that energy consumption.
In the case where the load is supplied exclusively by energy purchased from the grid, the annual cost amounts to €8950.03. The introduction of a photovoltaic system already allows for a significant reduction in grid consumption, resulting in savings of 40.7%.
With the integration of the hydrogen system, there is an additional reduction in energy costs. In Case I, the annual cost reduces by a further 1.4% compared to the case with only a photovoltaic system. In Case II, with improved hydrogen system efficiency, the savings are even higher, reaching 43.6%.
In addition to analyzing the annual cost associated with energy purchases, it is equally important to consider the environmental impact of the system. According to the Portuguese Environment Agency, the emission factor in mainland Portugal in 2023 was 0.092 t CO
2eq./MWh (92 g/kWh) [
52]. Based on this value, CO
2 emissions corresponding to the different scenarios were estimated.
Figure 10 shows the emission values associated with each of the case studies mentioned above.
In the reference scenario, in which all energy consumed is purchased from the grid, annual emissions of approximately 8193 kg of CO2 are recorded. This value represents the worst environmental performance among the cases analyzed, given that all energy comes from a source with a positive emission factor.
With the introduction of photovoltaic production, there is a significant reduction in emissions, falling to around 4852 kg of CO2. This reduction results from the partial replacement of purchased energy with local renewable production.
In scenarios that integrate the hydrogen system, environmental performance is even more favorable. In Case Study I, emissions fall slightly to 4747 kg, while in Case Study II they reach their lowest value, with 4618 kg of CO2. This improvement stems from the system’s ability to store surplus renewable energy in the form of hydrogen and use it later through the fuel cell.
In both analyses, economic and environmental, there is a significant impact from the integration of renewable energy sources, with a significant reduction in both costs and emissions. However, with the introduction of the hydrogen production, storage, and consumption system, there is not such a marked difference, although there is a slight additional decrease in both indicators.
This limitation is related to the amount of surplus energy produced by the photovoltaic system. Since the system is not oversized, photovoltaic production is, in most hours, approximately equivalent to the load requirement during periods of maximum solar exposure. Thus, there is not enough surplus energy generated to take full advantage of the hydrogen system and, consequently, achieve more significant reductions in costs and emissions.
To complement the two previous case studies, the impact of the increase in photovoltaic production capacity was assessed in relation to the baseline scenario (Case I). The increase in solar production was directly reflected in hydrogen production, which rose from 60.9 kg in Case I to 256.3 kg with a 50% increase in photovoltaic capacity and 456.7 kg when that capacity was doubled. At the same time, there was a significant reduction in energy purchased from the grid, around 6.3 and 11.2 MWh in the respective scenarios, as well as a decrease in CO2 emissions of approximately 580 kg and 1 tonne, while the self-supply rate increased from 42.0% to 49.1% and 54.6%. Despite the overall improvements, the marginal gain between the 50% and 100% increases is less significant.
6. Conclusions
This study proposed and evaluated the implementation of an optimized energy management model in microgrids, integrating renewable energy sources, green hydrogen production by electrolysis, storage in pressurized reservoirs and subsequent consumption by fuel cells. The main objective was to analyze the economic and environmental benefits of incorporating these technologies in a representative annual scenario.
By comparing different scenarios, it was possible to verify that the simple introduction of photovoltaic production already allows for a significant reduction in annual energy costs (around 40.7%) and CO2 emissions (around 40.8%) when compared to a system that is totally dependent on the electricity grid.
The inclusion of the hydrogen system (production, storage, and use) brought additional, albeit more modest, benefits. In the scenario with real data, there was an additional reduction of 1.4% in cost and 2.2% in emissions. In the optimized scenario, with higher theoretical efficiencies, these reductions rose to 3.6% in cost and 4.8% in emissions, compared to the case with photovoltaics alone.
The main limitation to the greater impact of the hydrogen system is related to the reduced surplus production of the photovoltaic system. Without oversizing solar generation, the surplus available for electrolysis is limited, restricting the intensive use of hydrogen as a storage vector.
In addition, the developed mathematical model demonstrated highly satisfactory performance, proving to be both robust and adaptable. Its structure is readily scalable to larger systems and adaptable to alternative configurations, such as microgrids with hybrid systems integrating hydrogen and lithium batteries.
In future work, the study may be extended to long-term horizons of up to 20 years, incorporating degradation rates and the expected useful life of system components. This will enable more comprehensive techno-economic assessments, including indicators such as the Levelized Cost of Hydrogen (LCOH), stack lifetime and replacements, and compression/storage costs, providing a broader perspective on the competitiveness of the proposed system.