One of the most promising use cases of 5G/IMT2020 is the unmanned aerial vehicle (UAV). Due to their small size, the UAVs are resource constraint devices. To this end, this paper proposes an offloading algorithm for UAVs to assist in the execution of computationally intensive tasks. The proposed algorithm provides two UAV offloading methods. The first offloading method is the air-offloading, where a UAV can offload its computing tasks to nearby UAVs that have available computing and energy resources. The second offloading method is the ground-offloading, which enables the offloading of tasks to an edge cloud server from the multi-level edge cloud units connected to ground stations. The proposed algorithm is energy- and latency-aware, i.e., it selects the execution device and the offloading method based on the latency and energy constraints. The intensive algorithm simulation over reliable conditions for various scenarios with different cases for each scenario is conducted and results are presented.