Programming an Arduino via ESP8266 AP

Hello.

I have an idea for a project which involves connecting an arduino to a wifi network. However, I would like to be able to connect the arduino to a different wifi without reprogramming directly.

I had a remote idea, no idea if it would work, but I was thinking that maybe the Arduino checks for a connection, and if it doesn't get one, it enters AP mode. My question is, can the arduino be programmed using an ESP8266 on AP mode?

Another solution (outside the arduino and completely into ESP8266 realm) would be for the ESP8266 to enter AP mode if it can't find a wifi connection, and then connecting to it and sending it some command to connect it to an specific site and then reseting the whole system. I did find this library which does exactly that, but it's meant to be programmed into the module and not into the Arduino.

Help would be greatly appreciated.