A decision-support tool (ORES) in the form of a linear program is developed to determine the optimal investment and operating decisions for residential energy systems. It shows how energy conversion units such as a cogeneration fuel cell, a heat pump, a boiler, photovoltaic panels and solar thermal collectors can be combined with energy storage devices, consisting of a battery and a hot water tank, to drive down total yearly energy costs and CO2 emissions while meeting space heat, hot water and electricity needs. Under the assumption of perfect demand and production forecasts and depending on how the dwelling is allowed to exchange electricity with the grid, cost reductions between 5 and 60% are possible, whereas emissions can be cut by 45–90% with respect to a base case. Stochastic programming is used effectively to reduce the sensitivity to uncertainty in weather parameters. The resulting cost increase is limited to 1.2%. Decision rules are implemented to account for unforeseen variations in electric load. If it is assumed that peak loads can occur at any instant of the optimization horizon, energy costs rise by 9%, which in off-grid scenarios, are driven by the installation of an about 50% bigger battery system.