Today, the IoT has become a vital part of our lives because it has entered into the precise details of human life, like smart homes, healthcare, eldercare, vehicles, augmented reality, and industrial robotics. Cloud computing and fog computing give us services to process IoT tasks, and we are seeing a growth in the number of IoT devices every day. This massive increase needs huge amounts of resources to process it, and these vast resources need a lot of power to work because the fog and cloud are based on the term pay-per-use. We make to improve the performance and cost (PC) algorithm to give priority to the high-profit cost and to reduce energy consumption and Makespan; in this paper, we propose the performance and cost–gray wolf optimization (PC-GWO) algorithm, which is the combination of the PCA and GWO algorithms. The results of the trial reveal that the PC-GWO algorithm reduces the average overall energy usage by 12.17%, 11.57%, and 7.19%, and reduces the Makespan by 16.72%, 16.38%, and 14.107%, with the best average resource utilization enhanced by 13.2%, 12.05%, and 10.9% compared with the gray wolf optimization (GWO) algorithm, performance and cost algorithm (PCA), and Particle Swarm Optimization (PSO) algorithm.