Temporary hit points last as long as the duration of whatever spell or effect grants them. If a feature that grants temporary hit points does not have a duration, they last until they’re depleted or you finish a long rest.
Temporary hit points are lost first, before you start losing your normal hit points. Once all your temporary hit points are depleted, the remainder of the damage carries over. So if you have 3 temporary hit points and take 5 damage, your temporary hit points are depleted and you take 2 damage.
Temporary hit points don’t stack from multiple sources. If you have them and receive more, you deice whether to keep the ones you have or take the new ones. So if you have 5 temporary hit points and a new effect grants 10, you end up with 10 temporary hit points, not 15.