In the bowl of a standing mixer fitted with the paddle attachment or in a large bowl using a handheld electric mixer, cream the butter and sugar on medium speed, scraping down the bowl as needed with a spatula. Beat in the egg yolks, scraping down side of bowl as needed to incorporate.
In a separate medium bowl, sift the flour, cocoa powder, and salt. Beat the flour mixture into the egg mixture on low speed in three batches, stopping as soon as it's incorporated. Form the dough into a ball with your hands, then flatten it slightly into a disk. Wrap in plastic wrap and chill until slightly more firm, 30 minutes or up to 1 day (if dough is very firm when you remove it, let sit at room temperature for 10 minutes).
Remove the dough and reserve a golf ball-size piece. Place the remainder in the center of a 13x4-inch fluted rectangular tart pan or 9-inch round tart pan with a removable bottom. Press the dough across the bottom and up the sides of the pan to form a very thin (1⁄8-inch) layer, making sure the dough is not too thick in the corners. Dock the bottom of the dough about every 2 inches with the tines of a fork, and place the tart pan on a baking sheet. Freeze until firm, about 10 minutes.
Set a rack in the top third of the oven and preheat to 375°. Bake about 8 minutes; check to see if dough has puffed up, and if so press it back down using a spatula or by poking with a fork (if holes form, you can patch them later with the reserved dough). Bake until set, about 15 minutes more. Remove. While the crust is still hot, gently patch any holes with pieces of the reserved raw dough (the residual heat will fuse them together). Let cool completely in the tart pan. Crust can be made up to 1 day ahead. Once cooled, wrap in plastic wrap.
Quickly pour the chocolate filling into the prepared tart shell set on a baking sheet, tilting the tart pan as needed to help evenly distribute and fill the corners. Bake until the filling is just set but slightly jiggly in the center when the pan is shaken, about 20 minutes.
Remove and let cool 5 minutes. Sprinkle the tart generously with sea salt and lightly with chopped espresso beans if using. Transfer the tart pan to a cooling rack. Let cool completely. Carefully remove the fluted rim, then slice the tart and serve with whipped cream if desired. Tart can be made ahead. Once fully cooled, wrap in plastic wrap. After 1 day, store in the refrigerator.