In fog computing, end-users can offload the computation-intensive tasks to the fog node in the proximity. Additionally, the fog nodes also offload these tasks to the cloud and neighboring fog node to seek additional computational resources. In this paper, we propose an offloading strategy in fog computing to minimize the cost that is a weighted sum of energy consumption and total delay for the task processing per end-user. We take the heterogeneous nature of the fog computing nodes that have different CPU frequency to process the tasks. We aim to find an optimal amount of task data to be either locally processed or offloaded to the preferable fog node and the remote cloud under the energy and delay constraints. We then formulate the optimization problem into a non-convex quadratically constrained quadratic program. We further provide an efficient solution to this problem by semidefinite relaxation. Finally, our proposed offloading scheme is evaluated by the simulation to demonstrate the offloading profile and optimal cost of the offloading with a wide range of parameter settings.