Integration of renewable energy sources in microgrids can be achieved via demand response programs, which change the electric usage in response to changes in the availability and price of electricity over time. This paper presents a novel control algorithm for joint demand response management and thermal comfort optimization in microgrids equipped with renewable energy sources and energy storage units. The proposed work aims at covering two main gaps in current state-of-the-art demand response programs. The first gap is integrating the objective of matching energy generation and consumption with the occupant behavior and with the objective of guaranteeing thermal comfort of the occupants. The second gap is developing a scalable and robust demand response program. Large-scale nature of the optimization problem and robustness are achieved via a two-level supervisory closed-loop feedback strategy: at the lower level, each building of the microgrid employs a local closed-loop feedback controller that processes only local measurements; at the upper level, a centralized unit supervises and updates the local controllers with the aim of minimizing the aggregate energy cost and thermal discomfort of the microgrid. The effectiveness of the proposed method is validated in a microgrid composed of three buildings, a photovoltaic array, a wind turbine, and an energy storage unit. Comparisons with alternative demand response strategies reveal that the proposed strategy efficiently integrates the renewable sources; energy costs are reduced and at the same time thermal comfort of the occupants is guaranteed. Furthermore, robustness is proved via consistent improvements achieved under heterogeneous conditions (different occupancy schedules and different weather conditions).