In the Netherlands, 60% of the consumed energy is for the thermal demand of buildings and industrial processes. More than half of this is for heating purposes of the built environment, predominantly by natural gas boilers. At present, only 4.5% of the primary energy input is from renewable energy sources. Recently, integration of renewable energy in the built environment and increasing energy efficiency of buildings are receiving much attention. Policies of the Dutch government are aimed at phasing out the use of natural gas for heating buildings entirely within a time period of 40 years. This will lead to a larger amount of district heating projects and heat pump installations the coming years, using renewable sources as bio-based fuels, solar PV, wind turbines, waste heat streams and underground thermal sources. Besides a shift from fossil towards renewable energy supply, often in the form of electrical energy generation (solar PV and wind turbines), part of the demand is also being electrified, e.g. heat pumps for the thermal demand and electric vehicles for transportation. As a consequence, the existing electricity grid experiences increasing demand and supply peaks due to fluctuating generation and fluctuating demand patterns. To overcome this, energy storage and smart control of devices can offer flexibility which may avoid problematic supply and demand peak loads. As renewable energy is generated on decentral levels in the vicinity of the real demand, regional and local energy generation, storage technology and smart control receive increasing attention. For these decentral energy systems, renewable energy supply and expected demand patterns determine which generation and storage capacity and which control scheme is as optimal as possible. This thesis is dedicated to the development of tools for these aspects and demonstrates how smart control leads to near optimal capacities and operation of renewable energy system assets. The thesis is centered around a smart grid demonstration project called "Meppelenergie". The purpose of this project is to demonstrate a completely renewable energy system for a new built district in which a biogas cogenerator supplies thermal energy for a district heating system and electrical energy for a group of heat pumps. The goal is to determine optimal capacities and control of generation and storage assets. Models for household space heating and cooling demand are developed, also for household hot water and electricity demand and for the state of charge of a thermal storage and electrical batteries. Of particular interest is the i ii ABSTRACT possibility to store thermal energy within concrete floor heating systems for which a model is developed and effects on thermal comfort and costs for residents are investigated. Within the thesis, the models are either used to generate demand patterns or for model predictive control as part of smart control methods. To determine optimal capacities of assets for two urban energy cases, a case specific model and a generalized system...