This paper utilizes the electric vehicles (EVs) connected to both the building and grid at the same time. In the building, the vehicle-to-home (V2H) operation is modeled. In the gird, the vehicle-to-grid (V2G) operation is studied. The EVs are modeled in the building connected to the electrical grid. The EVs are able to send energy to both grid and building. The building is also equipped with solar panels and electrical loads. Uncertainty of solar energy and loads are incorporated by stochastic programming. The optimization is implemented in GAMS to find the minimum daily cost. The optimal charging-discharging regime is denoted for EVs. The results illustrate that V2H-V2G operation can efficiently minimize the energy cost under solar-load volatility.