You should be able to:
- Backup the device to the new installation
- Transfer your purchases into a newly authorized library
- Recover any other media using third party tools as suggested in this post from forum regular Zevoneer
- Restore the device from the backup
This process should switch the association of the device to the new library, preserving the data and settings in your apps.
May also be prudent to attempt a backup to iCloud directly from the device before you start... Settings > iCloud > Storage & Backup > iCloud Backup > On. It won't save any media but it would preserve the general account settings and documents in case anything goes wrong while you are trying to extract your other data.
When you get it all fixed, make a backup!