To change the Apple ID on your device, you need to sign out of the Apple ID under the Settings app for Messages, FaceTime, iCloud, and iTunes & App Store. Once signed out of the old Apple ID, you can sign in with your new Apple ID. This article may provide some additional information.
To change the Apple ID for iCloud, go to Settings -> iCloud, scroll to the bottom of the screen, and select Sign Out. This will sign the device out of the iCloud account. It will not affect the account on any other devices you may have. Your iCloud data should still be available at https://www.icloud.com.
Once you select Sign Out, the device will ask if you want to delete or keep the data on the device. If you delete the data, all contacts and other iCloud data will be deleted from the device. If you keep the iCloud data on the device and sign in with a different Apple ID, the contacts and calendar data can be merged to the iCloud account for the new Apple ID.
Posted in: Apple ID