Increasing electrical energy consumption during peak hours leads to increased electrical energy losses and the spread of environmental pollution. For this reason, demand-side management programs have been introduced to reduce consumption during peak hours. This study proposes an efficient energy optimization in Smart Urban Buildings (SUBs) based on Improved Sine Cosine Algorithm (ISCA) that uses the load-shifting technique for demand-side management as a way to improve the energy consumption patterns of a SUBs. The proposed system's goal is to optimize the energy of SUBs appliances in order to effectively regulate load demand, with the end result being a reduction in the peak to average ratio (PAR) and a consequent minimization of electricity costs. This is accomplished while also keeping user comfort as a priority. The proposed system is evaluated by comparing it with the Grasshopper Optimization Algorithm (GOA) and unscheduled cases. Without applying an optimization algorithm, the total electricity cost, carbon emission, PAR and waiting time are equal to 1703.576 ID, 34.16664 (kW), and 413.5864s respectively for RTP. While, after applying GOA, the total electricity cost, carbon emission, PAR and waiting time are improved to 1469.72 ID, 21.17 (kW), and 355.772s respectively for RTP. While, after applying the ISCA Improves the total electricity cost, PAR, and waiting time by 1206.748 ID, 16.5648 (kW), and 268.525384s respectively. Where after applying GOA, the total electricity cost, PAR, and waiting time are improved to 13.72 %, 38.00 %, and 13.97 % respectively. And after applying proposed method, the total electricity cost, PAR, and waiting time are improved to 29.16 %, 51.51 %, and 35.07 % respectively. According to the results, the created ISCA algorithm performed better than the unscheduled case and GOA scheduling situations in terms of the stated objectives and was advantageous to both utilities and consumers. Furthermore, this study has presented a novel two-stage stochastic model based on Moth-Flame Optimization Algorithm (MFOA) for the co-optimization of energy scheduling and capacity planning for systems of energy storage that would be incorporated to grid connected smart urban buildings.