So what does Jesus tell him to do? Realize that he is seeking works righteousness by asking what he must do? Nope. Jesus tells him to keep the commandments. But maybe Jesus is just showing him his inability, catching him in his pride. Let's see.
The young man says, "which ones?" Now we could read this negatively as if he's trying to do the bear minimum. But we don't have to, and indeed we shouldn't. Remember this is 1st century Israel. There were any number of groups of self-appointed Jewish leaders with any number of versions of "the rules." There's no reason to think that this young man wasn't simply asking something like, "the commandments according to who? The Pharisees? The Essenes? The Zealots?" And Jesus' answer inclines us to think that something like this is the case. Jesus doesn't rebuke the young man. He answers him. In effect he says, "nothing special, just what Scripture says." In other words Jesus isn't just another guru offering a special, elite path to the Kingdom of God. He says that the path into the Kingdom is just the path of obedience to God's word.
Ah, but here's where it gets dicey. The young man claims to have done these things, and not just for a day or two, but from his youth (keep in mind he is a young man). He must be trusting in his own works, right? Well not if Jesus answer is any indication. Jesus doesn't rebuke him, or scoff. Jesus takes his answer at face value. Indeed, the boy hadn't said anything different than what he'd learned to say growing up singing the Psalms of David (Ps. 26.1; 75.10). Of course he's not claiming moral perfection here. He's saying that he has been faithful to the Covenant and kept God's commands, including the commands to offer sacrifice and repent when one sins.
Indeed, if the boy's problem is one of works righteousness Jesus only exacerbates it. Jesus does not tell him to stop relying on himself and his good works to earn his salvation. Jesus tells him to go and sell all he has and give it to the poor. That is, Jesus tells him to do a very significant good work. And lest we think that this was once again only to show the young man his inability, remember that such an interpretation would make his recorded response (i.e. going away sad/not following Jesus) the right one-- he learned that he couldn't do it. But surely we don't want to say that.
Jesus calls the young man to maturity. Jesus discerns the specific needs of this particular young man at this particular time and calls him to be faithful in this particular hour. This young man is trusting in his riches, at this time, and it's causing him to hold back from following the Messiah at this critical hour in the advancement of redemptive history. The young man is indeed young, and he's not yet mature (i.e. "perfect" in the ESV, teleios in Greek meaning "complete," or "mature" when referring to a person). At this moment he needs to cast off his earthly riches, trust in Jesus who is bringing the Kingdom and inherit the riches of the heavenly Kingdom-- not disembodied existence in the clouds, but a stake in the Kingdom that Jesus rules from the right hand of the Father beginning at his resurrection and ascension.
So the application of this story is not that we all need to quit thinking that we keep God's commands. In a very real sense, if we are faithful Christians, we do. We'd better. We are called to from Genesis to Revelation. Of course we sin, but then we keep God's command to repent.
And the application also isn't that since we're all rich as Americans we all need to sell all of our stuff and give our money to the poor. Some people might need to do that. But what Jesus was calling this young man to was maturity; the kind of maturity that is willing to lay aside what might be tempting right now, or what might make us feel comfortable and secure so that we can follow him, and then be gifted something much better. Make no mistake Jesus promises this young man treasure. And the qualifier "in heaven" doesn't mean "not really but just pretend." When Jesus says "no sex outside of marriage" he means to offer better sex in marriage. When he says "not right now" that doesn't secretly mean "no fun ever." Remember that Job was restored twofold. Look at the next paragraph. The disciples had given up a lot, but they would rule. And so will we. But sometimes Jesus means to make us mature first.