Where is ESP8266 TCP/IP stack defined?
The ESP8266 is a system-on-chip (SoC) WiFi solution. While a common setup is to have a dedicated microcontroller which talks to the ESP8266 with AT commands, it is in fact a fully functioning microcontroller which can be flashed with custom firmware.

The chip itself is physically made up of a Tensilica Xtensa core, a Winbond SPI flash, and a WiFi transceiver. These devices are all encased within the same physical package. The Xtensa architecture is a proprietary RISC architecture, but there is a toolchain available for it. There is a complete Arduino core and framework port for the ESP8266, which allows you to write your own Arduino code for the ESP8266 and have it running directly on the SoC, without the need for an external microcontroller. You can of course ignore the Arduino part and direclty compile your own native code using the Xtensa toolchain.

The firmware on the ESP8266 is usually what handles networking. If you look at the ESP8266 Module Quick Start Guide you can see that the AT commands are used to manage IP addresses and create TCP/UDP packets. The actual networking stack is in the firmware. In this particular case it is part of the closed-source Expressif firmware. Expressif firmware, which has an open-source SDK (thanks to Jack Creasey for this!)

In the case of installing the Arduino core on an ESP8266, we can see that the included libraries handle the networking, including Ethernet, DHCP, DNS, TCP/UDP, etc. - this allows you to customise the network stack if you wish.