for a script I want to scan for access points.
Usually I would call "iw dev wlan0 scan". But can be done when there is no wlan0 device configured?
Do I need to setup a temporary wifi configuration to be able to scan?
Or is there a more elegant solution?
sure, but what if there is no wlan0 device?
As long as the hardware is there and the driver/ firmware present and loaded...
You can try something like
iwinfo radio0 scan || iwinfo radio1 scan. This will either use an existing vif on radio0/radio1 for scanning or create one on demand if there is no suitable one yet.