According to yoga philosophy, there is a function in our mind called ahamkāra. In this Sanskrit word, aham means "I", and kāra means "maker". So, ahamkāra is the "I maker". The equivalent in Western conceptualization is the Ego. Ahamkāra is what creates the sense of this is who I am. Without ego, we would not identify with our mind, actions and body. The result would be an inability function in the world. It is due to ahamkāra that we know that it is "I" who is hungry and needs to eat; it is ego that enables us to realize we have to gather food, to work, to love, to do all that is part of life. Thus, ahamkāra is essential to our ability to function and be successful in our lives. This is why psychotherapists often help their clients increase their ego strength.
At the same time ego is essential, it also creates problems for us. Our true identity is so much more than our ego identity. But, few of us are enlightened and so we imagine that our ego identity is the sum total of who we are. So we identify with the ephemeral parts of ourselves, our material bodies, personalities, and emotions, and this results in suffering. We suffer over our desires, over whether we'll be successful or not, over relationships, over sickness, over death, over an infinite number of things.
Our suffering is further increased when ego extends itself to become egotism, and we hold ourselves in undue importance. Then our suffering greatly increases both for us and for those we come into contact with.
So what to do about ego and egotism?
Because ego is essential, we don't want to destroy it. Rather, we want to learn to work with ego in a positive way that minimizes our suffering. We can do this by gaining some perspective on what the ego is, what its function is, and how to avoid ego's excesses.
A simple way to attain perspective and overcome a tendency toward egotism is to realize just how puny we really are. Here's a link to a video that can help us do just this. It shows how small our world is in the vast scheme of the universe. https://youtu.be/923jxZY2NPI
Rather than kill the ego, we need to create an enlightened ego. Yoga-meditation is an unexcelled method to do this. Because the sincere practice of yoga leads to expanding awareness of what we truly are, this enables us to gain perspective of the limits and functions of ego so we can use it appropriately and not let it carry us overboard. In many ways, yoga is mind-training. We train our mind to serve our higher good rather than carrying out excessive demands of the ego. Actually, in the final step of yoga-meditation, when the final Self-realization is attained, one becomes the complete master of ego, and then can use ego as a very useful tool rather than being ego's slave.