May I suggest heading to the LoRaWAN academy for the LoRaWAN basics? It will provide you with a good working knowledge of the technology.
A node is not connected to a gateway. A node connects to the network (TTN). A gateway just received RF data and forwards it to the network if the CRC is correct and transmits data when instructed by the network. It is pretty dumb.
The state that you need to preserve contains (among other things) the session encryption keys, the address, uplink and downlink counters, spreading factor, transmission power, channel frequencies.
LoRaWAN ‘connections’ (the combination of session encryption keys, address and counters as saved by the node and the network) are valid for months. If you device just sends one packet every few months it will still work. So ‘keeping’ a connection is not an issue.
There are boards with ARM based controllers that integrate the LoRaWAN hardware that are able to keep RAM state while in very low power sleep. I don’t have a recommendation for a specific board right now, may-be one of the other forum users can chime in?
You should also search the forum, iirc someone posted some code to safe the state for esp32 devices.