(1) Back up all data from the Z3. (2) From the Home screen, select the Applications button. (3) Select Settings. (4) Select 'Personal' and then tap Back up & reset. (5) Uncheck 'Automatic restore' check box. (6) Under 'personal data' select 'Factory data reset'. (7) Select 'Reset phone'. (8) If you have a lockscreen passcode, enter it now. (9) Select 'Erase everything' to confirm.
If the Z3 cannot hold a charge for very long, it may mean that the battery is becoming permanently depleted. If this is the case, the battery will need to be replaced. Follow the battery replacement guide for the Sony Xperia Z3 found here.