Arduino and ESP8266 - how to send/receive data between serial and TCP port

I would ideally like the user of the project to be able to buy and ESP8266, connect it to the Arduino and have the sketch on the Arduino configure the ESP ready for use. The user sets the AP details in the sketch.

Ok, so I have got as far connecting the ESP8266 to a WiFi AP and given it an IP address. I now want to be able to send data from the Arduino serial to a TCP port and to receive data from the TCP port and pass it to the serial port on the Arduino. The idea is to be able to telnet into the TCP port and communicate with the Arduino. How do I go about this?

I have seen and am confused by much of the information online which seems to require a sketch to be uploaded to the ESP. But doesn't that overwrite the original firmware? A number of sketches have the ESP connecting to a server on another computer. Here I need to do the opposite - to be able to telnet from a PC and communicate with the Arduino over the ESP serial link. I expected this to be easy, but am now wondering whether this is even possible?

Finally, how does one set up a web portal on the ESP8266 so that the user can change the configuration of the device?

If anyone can point me at suitable clear tutorials on the subject, and by all means tell me if what I am trying to do is impossible, this would be appreciated.

Thanks. I think I have realised that the best way forward is to program the ESP8266 directly and I have now figured out how to add the ESP8266 board to the Arduino IDE.