Here's an example, assuming you have the online/offline-onstart/onend scripts created and saved in the /opt/retropie/configs/all folder.
Create a script that will toggle the online saving features, called Enable Online.sh:
#!/usr/bin/env bash
cp /opt/retropie/configs/all/online-onstart.sh /opt/retropie/configs/all/runcommand-onstart.sh
cp /opt/retropie/configs/all/online-onend.sh /opt/retropie/configs/all/runcommand-onend.sh
Create a similar script to disable the online saving, called Disable Online.sh
#!/usr/bin/env bash
cp /opt/retropie/configs/all/offline-onstart.sh /opt/retropie/configs/all/runcommand-onstart.sh
cp /opt/retropie/configs/all/offline-onend.sh /opt/retropie/configs/all/runcommand-onend.sh
Copy the 2 scripts in $HOME/RetroPie/retropiemenu and then restart EmulationStation. There should be 2 new entries under the RetroPie system with for the 2 scripts, which you can execute when needed (i.e. for online play or offline play).
The names of the scripts doesn't matter as long as you remember their purpose, you can name them as you like.