Preheat oven to 350°F (175°C) and bake pie crust for 10 minutes; let cool.
In a medium saucepan, whisk together sugar, cocoa powder, cornstarch, and salt.
Gradually whisk in milk until smooth and cook over medium heat until mixture thickens and comes to a boil.
Remove from heat; slowly whisk in egg yolks, then return to heat for 2 minutes, stirring constantly.
Remove from heat, stir in butter and vanilla until smooth.
Pour chocolate filling into the cooled pie crust.
Refrigerate for at least 2 hours until set.
Top with whipped cream before serving, if desired.