The poem is generally intended to encourage self-confidence but not self-righteousness. Kipling uses these dichotomies throughout the poem. In the first stanza, the speaker encourages self-reliance but ends with a warning not to be or appear too confident or self-important.
It is important to read closely to see which pronouns refer to which nouns or concepts. In this first stanza, the speaker exhorts the listener to trust himself when others will doubt. When others ("they" or "them") doubt you, continue to trust yourself. Be confident but not over-confident, no matter what "they" say. In this sense, "they" are others who might doubt you. "They" are people who might discourage you or try to tear you down.
In the second stanza, the speaker notes that your (the listener's) dreams might be "twisted by knaves" when applied in some public way. Again, this is a warning that your dreams could be challenged or manipulated by others. It is up to you to persevere in spite of "them," who are, in this case, the "knaves." Given these initial uses of "they" and "them," it seems that "them" in the third stanza is used in a similar way to indicate other naysayers. But this is not the case.
In that second stanza, the speaker says to treat Triumph and Disaster the same. They are "impostors" which means they are simply labels and are temporary. So, in the third stanza, the speaker encourages you to be willing to risk all of your winnings. Considering that triumph and loss are temporary makes it easier to move on in either case. Even if you lose it all, do not lose heart or determination. In this case, the "them" refers to "heart and nerve and sinew" spoken of in line 21. The speaker means that you should hold on to your heart (faith/hope), nerve (determination), and sinew (that which holds you together, which hold muscle to bone). Hold on to "them," the things which keep you together and motivated, even following a crushing loss.