An optimal energy management is addressed in the residential building. The residential building is equipped with renewable energies including wind turbines and solar panels. The uncertainty of renewable energies is modeled by stochastic programming. The demand response program is simultaneously adopted to handle such uncertainty and reducing the energy cost. In this respect, four different loads are modeled in the building including interruptible, constant energy, constant power, and uninterruptible loads. The aforementioned loads are properly adjusted and dispatched for minimizing the energy cost as well as to deal with renewable energy intermittency. The bidirectional operation is modeled for the building and it can send energy to the grid or receive it from the upstream network. The results verify that the introduced model can efficiently harvest all possible energy of the wind-solar system, handle the uncertainty, minimize the cost, and operate as off-grid. All of these purposes are achieved by optimal dispatching and adjusting of the loads through the proposed demand response program.