The proglem was becasue phone was not used for a long time, had manual setting of time and date
and had a time of 2016 whereas now it is 2018. Once I updated the date and time manually to the current time
and then attempted login/sync to microsoft account, things started working correctly. Prior to this it could not sync to any account nor connect to internet even if wifi was connected.