With the rapid development of Internet of Things (IoT) technologies, fog computing has emerged as an extension to the cloud computing that relies on fog nodes with distributed resources at the edge of network. Fog nodes offer computing and storage resources opportunities to resource-less IoT devices which are not capable to support IoT applications with computation-intensive requirements. Furthermore, the closeness of fog nodes to IoT devices satisfies the low-latency requirements of IoT applications. However, due to the high IoT task offloading requests and fog resource limitations, providing an optimal task scheduling solution that considers a number of quality metrics is essential. In this paper, we address the task scheduling problem with the aim of optimizing the time and energy consumption as two QoS parameters in the fog context. First, we present a fog-based architecture for handling the task scheduling requests to provide the optimal solutions. Second, we formulate the task scheduling problem as an Integer Linear Programming (ILP) optimization model considering both time and fog energy consumption. Finally, we propose an advanced approach called Opposition-based Chaotic Whale Optimization Algorithm (OppoCWOA) to enhance the performance of the original WOA for solving the modelled task scheduling problem in a timely manner. The efficiency of the proposed OppoCWOA is shown by providing extensive simulations and comparisons with the original WOA and some existing meta-heuristic algorithms such as Artificial Bee Colony (ABC), Particle Swarm Optimization (PSO), and Genetic Algorithm (GA).