The generation of energy from renewable sources is a fundamental aspect for the sustainable development of society, and several energy sources such as solar, biomass, biogas, and wind must be used to the maximum to meet existing needs. In Chile, there are villages that are off-grid. A real case study is presented in this research. To meet the needs of this village we have proposed a mathematical optimization model using a CPLEX optimizer to generate the necessary energy power while minimizing the cost of energy (COE). In this study, different scenarios have been evaluated with respect to the existing energy availabilities, for example, in different periods of the year, demonstrated in terms of economic costs, the viability of resources such as biomass and biogas, and the viability of the energy production of wind power given the associated high costs. Finally, the effect of the use of renewable energy in consideration of CO2 emissions is studied in our research.