Syrian rebels have reached a deal with the government for the withdrawal of opposition fighters, civilians and wounded people from the city of Homs, where they have been under siege for two years.