## 1 Introduction
Despite numerous studies, limited attention has been given to hybrid system optimization tailored explicitly for rural areas with abundant livestock biomass resources, simultaneously addressing economic and environmental goals. Thus, this study bridges this gap by focusing on the optimal integration of biogas generators, solar PV, and battery storage, evaluating trade-offs between cost, emissions, and reliability, specifically in semi-remote rural settings. Furthermore, its emissions analysis helps decision-makers choose solutions that align with environmental goals. As in [42], hydrogen integration in HESs significantly cuts carbon emissions compared to fossil-based setups. Similarly, HOMER's simulations highlight hydrogen's potential to reduce reliance on DG and other high-polluting fuels. Also, ref. [43] demonstrates how using solar and wind energy to power desalination plants can cut carbon dioxide emissions by up to 80%, highlighting the advantages of renewable-driven processes in addressing water scarcity without harming the climate. In both studies, HOMER's optimization capabilities reveal practical, eco-friendly pathways for transitioning to cleaner energy solutions and emphasize the importance of supportive policies in facilitating large-scale adoption. These features have established HOMER as a trusted tool, guiding policy and research decisions and paving the way for innovative, sustainable energy projects. In the context of the present study, addressing both economic constraints and reliability demands is crucial. This work aims to bridge the gap between current limitations and a forward-looking energy future by examining the existing power infrastructure and considering new, more sustainable options. HOMER's ability to optimize multiple energy sources, model local conditions, and evaluate cost and performance trade-offs makes it especially well-suited for developing a feasible, efficient energy solution that aligns with the region's needs. Recent advances in RES optimization have emphasized the importance of robust control strategies and efficient system integration methods [44; 45]. These methodologies provide valuable insights into improving the reliability and cost-effectiveness of hybrid systems similar to the proposed configuration. In this context, evaluating the control aspect of the system is particularly crucial, as effective control strategies directly influence operational efficiency, system stability, and the ability to adapt to varying demand and resource conditions. Therefore, a thorough analysis of control mechanisms is essential for the successful implementation and long-term performance of hybrid renewable systems. Spain's current energy policy landscape, particularly the Integrated National Energy and Climate Plan (PNIEC 2021-2030), strongly supports expanding renewable energy sources, energy efficiency, and energy sector decarbonization. Key regulatory developments, such as Real Decreto 244/2019 promoting self-consumption and decentralized renewable generation, have created favorable conditions for deploying RESs in rural and semi-remote regions. These policies incentivize renewable integration and provide economic mechanisms--such as feed-in tariffs and targeted subsidies--that enhance the financial viability and practical feasibility of hybrid solutions combining photovoltaic, biomass, and storage technologies. Thus, the development and optimization of HESs, as presented in this study, align closely with national energy goals and benefit from the existing supportive regulatory framework. This study contributes to the existing literature in several important ways. Firstly, it addresses a critical gap by optimizing a hybrid renewable energy system tailored for semi-remote rural areas experiencing frequent power outages despite grid availability. Although hybrid microgrid configurations have been explored in various contexts, few studies investigate locally sourced livestock waste as a primary dispatchable fuel alongside PV systems to enhance reliability in practice.