Ego is the central operating system in the field of consciousness. Jung listed five functions that the ego operates with:
1) Stability of personality: Ego tries to keep general personality reasonable stable over time. This is to keep you from suddenly acting outside of your character and/or your strongest sides(for example dominant function or some other habits that define your personality) that you have developed over time.
2) Stability of identity: Our self awareness/self identity remains stable over time. This is to keep you from thinking that you are suddenly a different person than you were before you went to sleep, but also has long term effect.
3) Cognition: Ego helps us to process information(via thinking or feeling), to problem solve and to store memories.
4) Executive functioning: Our ability to deal with the everyday demands of the world. For example how to use a fork and knife or brushing teeth in the evening/morning.
5) Reality testing: Expect and obey the natural laws of physics. You dont start to think that you can fly off from a top of a roof.
Some mental conditions can weaken some of these functions temporarily. For example a severe case of schizophrenia will cause trouble with all of those. Depression can turn someone who is identified with happy go lucky personality to have extremely grim view towards life, or turn a thinking type to rely on his feeling or P functions more than thinking.
While ego is ultimately a good thing to have(for the listed processes that it offers), sometimes your ego can hold too tightly onto something that is not healthy. For example making you rely too much on dominant(and aux to lesser degree) function. Or if one has adapted a habit of taking drugs everyday and became an addict, ego tries to keep this habit going on. Personally i think that all problems with conscious attitudes are at least partially due to ego wanting to hold on to something that may not be good in the long run, for example ENFP having too high ideals that she cannot stop from trying to achieve, even tho they are unrealistic.
So in some situations it is healthy to go against the needs of your ego, and often inner conflicts are due to unconscious wanting some change, but ego wants to hold on to what already is.