Buildings are the main energy consumers across the world, especially in urban communities. Building smartization, or the smartification of housing, therefore, is a major step towards energy grid smartization too. By controlling the energy consumption of lighting, heating, and cooling systems, energy consumption can be optimized. All or some part of the energy consumed in future smart buildings must be supplied by renewable energy sources (RES), which mitigates environmental impacts and reduces peak demand for electrical energy. In this paper, a new optimization algorithm is applied to solve the optimal energy consumption problem by considering the electric vehicles and demand response in smart homes. In this way, large power stations that work with fossil fuels will no longer be developed. The current study modeled and evaluated the performance of a smart house in the presence of electric vehicles (EVs) with bidirectional power exchangeability with the power grid, an energy storage system (ESS), and solar panels. Additionally, the solar RES and ESS for predicting solar-generated power prediction uncertainty have been considered in this work. Different case studies, including the sales of electrical energy resulting from PV panels' generated power to the power grid, time-variable loads such as washing machines, and different demand response (DR) strategies based on energy price variations were taken into account to assess the economic and technical effects of EVs, BESS, and solar panels. The proposed model was simulated in MATLAB. A hybrid particle swarm optimization (PSO) and gravitational search (GS) algorithm were utilized for optimization. Scenario generation and reduction were performed via LHS and backward methods, respectively. Obtained results demonstrate that the proposed model minimizes the energy supply cost by considering the stochastic time of use (STOU) loads, EV, ESS, and PV system. Based on the results, the proposed model markedly reduced the electricity costs of the smart house.