The plot thickens...
Sorry, it's not clear to me what you're trying to do. I thought you had a Nano and an ESP8266, and you were trying to use the ESP8266 as a WiFi module to make the Nano connect to a WiFi network...right?
The way you wrote your initial post could also be read as "I wrote code on an ESP8266 and when porting it to the Nano, I didn't get the WiFi to work" which would be obvious, since the Nano doesn't have WiFi.
Anyway, question still stands - what's the Nano doing there anyway? Why not keep things simple and do everything with the ESP8266? Yeah, you don't have one right now. Have you looked how much they cost? They're quite cheap.