The easiest way to do this is to use the DiRT utility (you can snag the latest from www.CiscoUnityTools.com). You can backup 3.1(2) with DiRT, install a new 3.1(2) Unity on a new server (it can be in a different domain, on a different server name etc... no problem) - restore your 3.1(2) backup and then upgrade from there to 4.0. There's a help file and training video out on the tool's home page that may be helpful to you here.
with DiRT you have to restore to the same version you backed up so you can either do it this way or first upgrade your system to 4.0, then DiRT backup and restore onto a new 4.0 installation on a new box. I'd probably reccoemend doing the backup of 3.1(2) if the system hasn't been too stable for you.
Be sure to check out your database health with the latest dbWalker on your 3.1(2) system prior to backing up (again, you can always get the latest dbWalker from www.CiscoUnityTools.com).