The integration of distributed generation units and microgrids in the current grid infrastructure requires an efficient and cost effective local energy system design. A mixed-integer linear programming model is presented to identify such optimal design. The electricity as well as the space heating and cooling demands of a small residential neighbourhood are satisfied through the consideration and combined use of distributed generation technologies, thermal units and energy storage with an optional interconnection with the centralised grid. Moreover, energy integration is allowed in the form of both optimised pipeline networks and microgrid operation. The objective is to minimise the total annualised cost of the system to meet its yearly energy demand. The model integrates the operational characteristics and constraints of the different technologies for several scenarios in a South Australian setting and is implemented in GAMS. The impact of energy integration is analysed, leading to the identification of key components for residential energy systems. Additionally, a multi-microgrid concept is introduced to allow for local clustering of households within neighbourhoods. The robustness of the model is shown through sensitivity analysis, up-scaling and an effort to address the variability of solar irradiation.