1) To keep your city safe from battle, you can use items that prevent your city from attack. However, troops outside of your city are not protected. 

2) Use a teleport to move your city to a new place, away from incoming attacks. 

3) Join an alliance and teleport your castle to be close to your allies so that you can help protect each other. 

4) Build a hospital to protect more troops from being killed and avoid conflicts with more powerful players to minimize your loses.