You can find a room in a cheap guest house for around 50-100 dirhams (5-10 euros). You might even bargain for a cheaper price if you insist that you just need a place on the roof to lay down your sleeping mat.
Sleeping outside isn’t a smart move in the cities as you’ll most likely be robbed blind. In general if you’re planning to camp in the countryside it’s best to do so very discreetly as the local kids and drunks may come by to hassle you otherwise. Good luck in keeping it a secret from the village that a foreigner is sleeping outside.
Staying with a local family is the best way to get to know the culture. You’ll eat together with the family, watch TV with them and get taken around to all the cool places in town without an obnoxious guide making you crazy. Also once you have a local friend you are protected in that neighborhood.