It is what it is.
Righteous - state of being right, correct, justified
Self-righteous - the unfulfilled ideal of righteousness through effort or assignments of the self
Self-righteous does not only mean overly pious or concerned with rules. It literally means self righteous... because if we're truly honest nobody is trying to be righteous simply for the sake of it, show me someone who says they are and I'll show you a liar who is only attempting to justify his hidden sense of self-righteousness. Which is, of course, not righteous motivation.
I think the line seems blurred because many people follow a self-righteous ethic system which does not make a total, fair comparison without actually possessing righteousness. We can easily assign ourself as right or justified because most people would agree as they are in the same boat. This is why religious people may tend to be the worst offenders of a self-righteous attitude as they have a lot of "moral backing" (i.e. other people who are following the same selection of rules as they are) to reinforce their misconception.
However, making a total comparison of everything one person does against another, it seems clear to me that nobody should assign themselves this way.
for all have sinned and fall short of the glory of God (Romans 3:23)
This must be the #1 verse that religious people love to overlook. It seems very clear to me. This short clip might help illustrate.
YouTube - The Professional -- Everyone
So true righteousness is not a matter of what one does but rather where they place their faith and hope. Any time someone's hope is in themselves, they have a self-righteous attitude and 100% of the time they will be turning a blind eye to something which would prove otherwise. Instead, if someone puts their faith in Jesus they can exchange themselves for real righteousness and their actions will begin to reflect this.
God made him who had no sin to be sin for us, so that in him we might become the righteousness of God. (2 Corinthians 5:21)
This concept is the crux (har har) of Christianity and the difference between Christian belief and every religion (Islam, Buddhism, etc), that the focus is not on our ascent to god (self-righteous) but God's descent to us and bestowing a righteous state by Godly (not human) volition "so that none may boast". I'm a fairly skeptical person and I have a hard time not believing it because I'm pretty sure no human would invent a religion that doesn't glorify humanity in any way. Ironically, I've found many Christians to be self-righteous and I think it's sad, because they're crazy. Christian belief starts with realizing that you're wrong.