The increasing demand for sustainable energy solutions is driving the integration of various renewable energy technologies. Integrating electric vehicle batteries, photovoltaics, heat pumps, and thermal tanks into building energy systems offers a promising approach to enhancing energy flexibility and efficiency. However, research on such integrated energy systems is still in its infancy. Optimizing the configuration and operation of the system may lead to significant cost savings and improved energy management. A coupled model and simulation-based optimization approach are used to optimize the thermal tank capacity and key operational parameters to minimize the annual total cost. The results show that the integrated energy system reduces the annual total cost by 36.35% and monthly electricity bills by up to 69.26% compared to the base system. As for energy flexibility, only 13.91% of electricity demand is supplied by the grid during peak periods, and the monthly load coefficient, load cover ratio, and photovoltaic self-consumption ratio of the integrated energy system are significantly improved. This study demonstrates the economic and operational benefits of integrating various renewable energy technologies into building energy systems and provides new insights into their design and optimization.