It is certainly possible to change the engine while afloat, and if the footprint is the same it's a pretty simple job - depending on how easy it will be to lift the old engine out. You can rig a tackle off the boom to do that.
One thing to check: if the boat has a dripless seal like the PSS, disconnecting the coupling and removing the engine/gear will remove the sealing pressure and the seal will leak a lot. If it is a conventional stuffing box there's no problem. If it is dripless you can protect yourself by thoroughly taping the shaft collar to the seal tube to prevent those parts from separating.
Remove parts from the old engine such as alternators, manifolds etc to make the package smaller (and lighter) to clear the companionway and furniture during the lift out.
And even though the footprint is the same, check that other parts won't interfere with clearances once the engine is in place. The entire package may be shorter/longer which could also lead to necessary shaft mods, so do your homework first.
It is, in fact, better to do the final alignment while afloat since many boats "sit differently" in the cradle or on the hard.