As noted in previous posts, the governing code would be the energy conservation code adopted by your jurisdiction. You will have to look up what energy code is adopted based on your location for specifics. All references that I will be making will be based on the 2018 IECC as that is what NYS adopts (and what I am most familiar with). I will also be assuming you are talking about commercial buildings and not residential.
My belief is mechanical rooms or rooms that house electrical panels can have an occupancy switch, but it must have manual override. However, I may be wrong and can't find code ref help appreciated.
NEC 110.26(D) specifically bans the usage of occupancy switches for working space illumination. Per the 2018 IECC, mechanical rooms/electrical rooms are also not required to have occupancy sensors. Refer to C405.2.1 for the list of locations that are required to have occupancy sensors. Because mechanical rooms/electrical rooms are not specifically required to have occupancy sensors, there is no requirement to have the manual override.
Essentially the way the 2018 IECC reads is that occupancy sensors are required in the interior spaces noted in C405.2.1. For all other interior spaces, time switch controls (AKA time clock) is required as noted by C405.2.2. However, there are exceptions listed in C405.2.2 for certain spaces where time switch control is
also not required. If you fall under those exceptions, then both occupancy sensors and time clock are not required. However, in order to fall under those exceptions, a means to provide light reduction is required (ie, dimming or bi-level switching).
When designing the lighting controls for electrical/mechanical rooms, I utilize the "automatic shutoff would endanger occupant safety or security" exception per C405.2.2. For the most part, I only specify a toggle switch without light reduction methods. I know technically I am not satisfying the IECC, but nobody in their right mind will be dimming lights in an electrical/mechanical room. I have yet to be challenged by a contractor or AHJ. However, If I wanted to design to the letter-of-the law, then I would add either dimming or bi-level switching (but I don't because that's stupid).
I also believe in commercial you can have occupancy sensors but they must be used with a switch so they could be manually operated. Or am I full of beans?
For the most part, yes. If you have occ. sensors then you need manual control somewhere to allow for the lights to turn
off manually per C405.2.1.1(3). Lights may be turned on automatically under certain conditions. Refer to C405.2.1.1(2) for when automatic-on is allowable. Note that the switch does not necessarily have to be in the same space as the lights.