Building energy consumption has increased rapidly in the past decade, in particular for heat demand and electric vehicles, owning to the development of economy and improvement of living standard. Distributed Energy Systems (DESs), which can effectively improve the share of renewable energy in the energy mix, lower the energy cost and reduce environmental impact, is a promising approach to meet the increased energy demand. This paper presents a review of the system architecture of DESs for building decarbonization, including hybrid energy systems, energy storage technologies, building flexible loads, and electric vehicles. The uncertainties from both the environment and human interventions challenge the energy management due to the asynchrony between energy generation and energy consumption. Thus, the system should be optimally designed and operated to enhance the reliability, affordability, and flexibility of the DES. The paper highlights the adoption of optimization approaches. Finally, future trends and challenges are discussed. It is concluded that the digital transformation featured with IoT, AI, advanced machine learning, sophisticated optimization approaches, and Blockchain is the enabler for future smart cities.