For sure you can do it with a complete upper--slide, barrel,spring, etc. I've done it, only going the other way--adding a .40sw upper to a 92 fs lower. Works fine. 9mm and .40sw uppers are usually listed on gunbroker.com.
The Beretta forum frequently discusses this subject--www.beretta.com.
I believe the mags are interchangeable for casual use.
What isn't clear is whether you can just switch the barrels from .40sw to 9mm
and have a workable solution. I'll defer on that one.