How to run optimus-manager using startx only?

Okay fellas, really reaching here.

Essentially I am trying to go for a minimal install on my main rig. The problem is that it it’s an Nvidia-tel “gaming” laptop, so I have to use optimus-manager on my rig. I can’t seem to find the answer on how to accomplish this part of running optimus-manager in the optimus-manager wiki for startx-only installs:

I do not use a display manager (I use startx or xinit)

Just like above, you must make sure to run /usr/bin/prime-offload (as normal user) just after the X server is started, and /usr/bin/prime-switch (as root) after it has stopped.

My question is: How do I run /usr/bin/prime-switch as root after the X server has stopped?
Edit to clarify: I can switch between nvidia and intel graphics by logging out of X and manually inputting sudo /usr/bin/prime-switch into the console. It is just that I want to execute this command automatically when X stops.
Another update: Although I can get optimus-manager to switch to nvidia graphics by doing optimus-manager --switch nvidia into the terminal emulator, which logs me out of X, and then proceeding to input sudo /usr/bin/prime-switch into my tty console, and then inputting startx to pull up my X environment once more to enable the nvidia mode, optimus-manager does not retain this setting after a reboot. I.e., every time I reboot, I have to restart this process again each time in order to use my second monitor. How would I eliminate this reboot problem?

[Added this comment to the initial post above as the “Another update” section.]