How does he get away with repeatedly threatening Joffrey's life and well-being before he dies? It can't just be because Joffrey is so afraid of Tywin, as Tyrion's disrespect precedes his arrival.
Tyrion is acting Hand of the King and as such answers only to Joffrey and Tywin and Tywin isn't there.
Cersei: What are you doing here? This is the small council.
Tyrion: Yes., well, I, do believe the Hand of the King is welcome at all small council meetings.
Cersei: Our father is Hand of the King.
Tyrion: Yes, but in his absence…
Tyrion pulls out a letter. He hands it to Varys, who opens it, and begins reading it.
Varys: Your father has named Lord Tyrion to serve as Hand in his stead while he fights...
Game of Thrones, Season 2 Episode 1, "The North Remembers"
And Tywin actually orders Tyrion to keep Joffrey in line whilst he is in King's Landing as acting Hand until he returns.
Tywin: No one will stay here. Ser Gregor will head out with 500 riders and set the Riverland on fire from God's Eye to the Red Fork. The rest of us will regroup at Harrenhal. And you will go to King's Landing.
Tyrion: And do what?
Tywin: Rule. You will serve as Hand of the King in my stead. You will bring that boy king to heel, and his mother too, if needs be. And if you get so much as a whiff of treason from any of the rest – Baelish, Varys, Pycelle…
Tyrion: Heads, spikes, walls. Why not my uncle? Why not anyone? Why me?
Tywin: You're my son. Oh, one more thing. You will not take that whore to court. Do you understand?
Game of Thrones, Season 1 Episode 10, "Fire and Blood"
On top of that Tyrion is Joffrey's uncle and the Lannisters are raised to respect your family and treat them as your only allies, especially in public. Joffrey is also a spoilt brat and isn't used to people standing up to him and so isn't used to it initially so can't work out how to fight back to it. Instead he cries and complains but doesn't have the will to act on it.