Although fog computing is a new research topic, there are robust and integrated solutions for service activation management and how to distribute IoT services over available fog computing services resources. This paper presents a multi-objective gray wolf optimization (GWO) solution for more efficient fog computing service scheduling and activation management. This solution utilizes a multi-objective function in the resource allocation process by developing and improving the proposed algorithm to check the status of resources and manage tasks. The main purpose of this study is to create a trade-off between energy consumption and task execution time. This research has presented a two-stage multi-objective approach to solve the scheduling and task offloading problem. First, the GWO algorithm is used to solve the scheduling problem, and then container migration is used to solve the task offloading problem and appropriate resource allocation. Container migration causes an idle physical server to turn off, reducing power consumption, improving imbalance, reducing latency, and improving efficiency. The proposed method has been compared with three scenarios with 700 nodes, 1000 nodes, and 5000 nodes. The proposed solution has been implemented and simulated in iFogSim and compared with five classical algorithms. The analytical results indicate the better performance of the proposed strategy with average execution time for host selection averages a reduction of 15, 20, 25, 20, and 21%, respectively, compared to Particle swarm optimization (PSO), Ant colony optimization (ACO), Grasshopper optimization algorithm (GOA), Genetic algorithm (GA), and Cuckoo optimization algorithm (COA), 12% reduction in average time required for reallocation container, and the service-level agreement (SLA) violation rate is maintained in the range of 9-10/% compared to all other solutions.