This paper proposes an energy management scheme for a shared facility controller (SFC), which is equipped with solar panels and is connected to other energy entities in a smart grid. The objective is to minimize the operational cost to the SFC by increasing the use of solar energy. In this context, an optimization problem is formulated for the SFC by giving its requirement a priority, whereby the SFC can also sell the solar energy to other entities if there is any surplus. To enable this, the concept of a virtual cost (VC) is introduced, which is an estimate of the cost to the SFC at a future time slot based on currently available information. The VC is further used to leverage the charging and discharging of the SFC's battery. An algorithm, which runs in real-Time, is proposed to manage the optimal charging and discharging of the SFC's storage and to trade energy with different entities in the system to optimize the cost at any given time. Numerical case studies are provided to show the beneficial properties of the proposed scheme.