@settisuresh, your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advise on) your project
See About the Installation & Troubleshooting category.
I'm not that familiar with the ESP8266. You can use one of the spare serial ports on the Mega and connect it to the ESP8266's serial port.
- A connection with the ESP8266's serial port might interfere with uploads to the ESP8266.
- The ESP8266 is a 3.3V device; you will need a voltage divider between the used Mega's TX and the ESP8266's RX.