In Arduino, you can do this with WiFi.mode(x), where x can be WIFI_AP, WIFI_STA, WIFI_AP_STA or WIFI_OFF, for example:
WiFi.mode(WIFI_STA);
will set the ESP into client ("Station") mode.
I also use a little "reset" script in a separate sketch, but I have avoided using persistent...
WiFi.softAPdisconnect();
WiFi.disconnect();
ESP.eraseConfig();
while(1); // deliberately crash
The forced crash is because apparently there is a bug in the SDK firmware / hardware that ESP.restart doesn't always clear things - again this may have subsequently been fixed.
Next time the code comes up I nake sure the following runs:
WiFi.mode(WIFI_STA);
WiFi.setAutoConnect(true);
Because for my project(s) I always want my devices to autoconnect in STA mode (which is the factory-delivered state)
WiFi.softAPdisconnect();
WiFi.disconnect();
WiFi.mode(WIFI_STA);
delay(100);