Proper sizing of energy systems is a key aspect that allows avoiding overestimated installation costs or failures in operation and dispatch. However, most of the available sizing tools focus on systems dedicated only to electrical loads, omitting combined energy systems with simultaneous supply of various thermal demands. This study presents an adaptation of an existing open access techno-economic optimization model for broadening the design tool for small-scale energy systems supplying both, electrical and thermal needs. For this, a new typology of an energy system was proposed considering the use of biogas, solar energy and adding thermal components. This was followed by modifying the model framework, constraints equations and objective function, which is the net present cost of the system. Once the design tool was verified a model was constructed to analyse the feasibility of a polygeneration plant for an association of 30 small dairy farms. The developed model was able to optimize the sizing of the main system components for different proposed scenarios, encompassing supply of electricity, refrigeration, biogas for cooking and fertilizers. For the selected application it was found that the aggregated cost of producing electricity and heat ranges from 0.044 to 0.070 USD/kWh; the penetration of solar energy can reach up to 32%; while the annual potential savings of CO2 emissions of applying the solution ranges from 109 to 127 ton of CO2.