This paper presents the definition of a detailed optimization model for planning the operation of a standalone hybrid microgrid. The mathematical model is expressed in a general way in order to handle a large number of microgrid configurations in which the demand of different goods (storable or not) has to be fulfilled, as AC and DC electricity, heat, cooling, drinkable water and ice production. The operation of the microgrid is defined by a rolling-horizon strategy that includes solving of a mixed integer linear problem. The goal of the optimization problem is to define the programmable units schedule that leads to the minimum operating cost, ensuring that the demand of each good is fulfilled and exploiting the forecast of production and consumption of non-programmable units over a certain time horizon. The model handles multi-input and multi-output programmable units, considering part-load performance curves, start-up penalizations and several other operation constraints. To demonstrate the model ability, the paper addresses two examples of microgrid configuration: the first test case shows the operation cost reduction attainable with this strategy in comparison with commonly adopted heuristic dispatch strategies; the second one demonstrates the capability to manage a complex system, provided with an Organic Rankine Cycle power system powered by both a biomass boiler and a solar Fresnel collector.