Microgrid works as a local energy provider for domestic buildings to reduce energy expenses and gas emissions by utilising distributed energy resources (DERs). The rapid advances in computing and communication capabilities enable the concept smart buildings become possible. Most energy-consuming household tasks do not need to be performed at specific times but rather within a preferred time. If these types of tasks can be coordinated among multiple homes so that they do not all occur at the same time yet still satisfy customers’ requirement, the energy cost and power peak demand could be reduced. In this paper, the optimal scheduling of smart homes’ energy consumption is studied using a mixed integer linear programming (MILP) approach. In order to minimise a 1-day forecasted energy consumption cost, DER operation and electricity-consumption household tasks are scheduled based on real-time electricity pricing, electricity task time window and forecasted renewable energy output. Peak demand charge scheme is also adopted to reduce the peak demand from grid. Two numerical examples on smart buildings of 30 homes and 90 homes with their own microgrid indicate the possibility of cost savings and electricity consumption scheduling peak reduction through the energy consumption and better management of DER operation.