Transfering my contacts from old phone to a new phone
When you add a new contact, your phone asks you where to store it (Phone, SIM, Google account). You can store your contacts in your Google account so when you sign in on another device, it will import your contacts.

For backing up SMS messages you can use SMS BackUp+ or a similar app. 

For more detailed explanation you can refer to HowToGeek's article on SMS backup.