Short term (IF'ing) can be used to shed fat while retaining lean mass and reduce the number of insulin spikes and gastric effect in a day.
Longer fasts are great for autophagy and for mental and spiritual purposes along with a generaly deeper detox.
The longer fast is not as lean mass sparing because that is not its function. You very well may end up with less muscle after the fast, but it should be of higher quality (body breaks down dysfunctional motor units for protein first hypothetically). So asking "how I do a long fast and not lose muscle...." is going to be a bit paradoxical. You will retain a good amount but by virtue of the fast you will need to loose a little bit.
Here is Mark's post if it helps you http://www.marksdailyapple.com/fasti...#axzz2E1MFVx5D
Then you can also search "Pklopp" for his posts and his website dedicated to IF'ing