Internet of Things (IoT) is revolutionising technical environment of traditional methods as well as has applications in smart cities, smart industries, etc. Additionally, IoT enabled models' application areas are resource-constrained as well as demand quick answers, low latencies, and high bandwidth, all of which are outside of their capabilities. The above-mentioned issues are addressed by cloud computing (CC), which is viewed as a resource-rich solution. However, excessive latency of CC prevents it from being practical. The performance of IoT-based smart systems suffers from longer delay. CC is an affordable, emergent dispersed computing pattern that features extensive assembly of diverse autonomous methods. This research propose novel technique resource allocation and task scheduling for device-device communication in mobile Cloud IoT environment based on 5G networks. Here the resource allocation has been carried out using virtual machine based markov model infused wavelength division multiplexing. Task scheduling is carried out using meta-heuristic moath flame optimization with chaotic maps. So, by scheduling tasks in a smaller search space, system resources are conserved. We run simulation tests on benchmark issues and real-world situations to confirm the effectiveness of our suggested approach. The parameters measured here are resource utilization of 95%, response time of 89%, computational cost of 35%, power consumption of 38%, QoS of 85%.