Artificial Intelligence for Building Energy Management in the Electricity Market and Transmission Power Flow Planning