The actor will play the title role in a run at the Trafalgar Studios in London's West End later this year.
It will be produced by Jamie Lloyd as part of the Trafalgar Transformed season which launched in 2013 with a production of Macbeth starring James McAvoy as the Scottish king.
Freeman's co-star in the hit detective show, Benedict Cumberbatch, will play Hamlet in the capital next year.
Freeman, who made his name playing Tim in the office, starred as Bilbo Baggins in Peter Jackson's Hobbit films.
His stage career includes performances at the Royal Court in London and the National Theatre.
Mark Gatiss, who co-writes Sherlock and stars as the detective's brother Mycroft in the show, also recently appeared in the Donmar Warehouse version of another Shakespeare play, Coriolanus.