Electricity Cost Minimization for a Residential Smart Grid with Distributed Generation and Bidirectional Power Transactions