Everything I do is motivated by greed/aversion. How to react? I just came to a very upsetting realisation :

Almost all my motivation for the things I do in my daily life (mostly playing the piano and studying math in college) comes from bad things, such as ego, greed or aversion. 

Here a some examples : 


I study very hard, because I wish to be better than everybody else, and prove myself that I am the most clever. In addition, I can't bear the fact of not understanding anything related to the classes. 
I play the piano in order to impress people listening to me and because I am craving to get better and better. 
I work hard in everything I do because I want to be admired by my friends and family. 


I also realized that it all leads to tension, pain and suffering. The problem is that I feel that just dropping these activities will certainly make things even worse. 

The question is  how should I replace these bad motivations by more skillful ones ? In other words, how to stay motivated to do the things you love without causing you pain ? Is it even possible ?
It is actually a nice realization, to see oneself like you did. I remember when I got mine, I was about 20 - and I was shocked to realize all my re-actions were motivated by desire to make myself look better in others' eyes. This means you are getting mature.

This is normal, especially when we are young(er). It is well known that small children are often extreme egoists - they don't even realize other people also have wants, interests, and problems. As we grow up, our circle of awareness grows and we begin to appreciate other people's perspectives and care about the world at large. 

You are right that the kind of drive you describe leads to tension and battles and suffering. And you are right that dropping it will not solve the problem. Suppressing it would only suppress the source of energy you have within yourself. It would also create problems in your personal life. What I suggest instead, is that, like Buddha did, you put this drive for perfection to the service of Enlightenment.

Meaning, you continue to strive to be perfect, but you expand your definition of perfection to include freedom from ego. All your actions can still be optimized to be as objectively flawless as possible, as long as you never act in order to feed your ego in your own or others' eyes. See what I mean?

Watch yourself for egoistic thoughts, motives, judgments - and eliminate them as soon as you notice any. Then continue to act as impeccably as possible for the greater good. This attitude - when you do your best to be as perfect as possible with the goal of eventually helping others, as opposed to doing it as food for your ego - is called "bodhi-citta", the mind of Enlightenment. You can get much more detailed instructions on this particular approach to Enlightenment in a book called "Cutting Through Spiritual Materialism" by Chögyam Trungpa. Good luck.