If I keep the lens on the camera will it be protected from dust and fungus? I keep my Nikon D5100 fitted with the lens in a plastic bag together with some silica gel.
Is that enough to protect it?
When attached to the camera and with the front lens cap on the camera will be pretty well protected from dust.
Protecting against fungus is a matter of keeping everything dry. Placing everything in a sealed plastic bag is only a good idea if the temperature is kept warmer than when the bag is sealed.
Air can hold a certain maximum amount of moisture according to it's temperature. If you bag the camera in a warm environment and then place the camera in a cooler one, then as the air in the bag cools it wont be able to hold as much moisture and condensation will form on the glass surfaces. As there's air inside the lens condensation can get inside from where it's very difficult to remove, allowing mould to grow.
The ideal solution is to keep your equipment unbagged and well ventilated in a humidity controlled environment.
I live in a very humid place. so my equipment has high risk of getting fungus.
What I do is: not keep it inside. Yes, youu heard me right :) .... I use my camera frequently and expose it to sun every now and then (sunlight is a good anti fungal solution).
Apart from that when you are not using your camera for long, make sure you have the silica gel (active) in the camera bag... you can reuse silica gel packets by simply heating them.
If you can afford to spend some money for some storage, get a dehumidifier or something called a dry box, where you can store all your digital gadgets for long-term storage.
As for the dust, leaving the lens on is more than enough.