For the brownies: Preheat the oven to 325 degrees F. Line a 13-by-9-inch baking dish with parchment, overhanging the edges by about 2 inches. Coat the parchment lightly with butter.
Melt the butter and chocolate chips together in a large heat-proof bowl set over simmering water, then remove from the heat.
With an electric mixer on low speed, mix the sugars into the chocolate mixture, then beat in the eggs on medium speed, one at a time, until fully incorporated. Beat in the extracts.
Mix in the flour on low speed until just combined. Fold in the coconut and nuts, if using, by hand. Fold in the salt.
Spread the mixture into the prepared baking dish and bake until a toothpick inserted in the center comes out almost clean, 35 to 45 minutes. Let cool completely on a rack before frosting.
For the frosting: Meanwhile, spread the coconut flakes on a baking sheet and bake, stirring once or twice, until lightly toasted, 8 to 10 minutes. Let cool.
Combine the butter and extracts in a large bowl and beat on medium-high until light, about 1 minute. Add the confectioners' sugar and beat on low until combined, then beat on high until light and fluffy, 1 to 2 minutes. Beat in the milk, 1 tablespoon at a time, until the frosting is easily spreadable.
Use the parchment overhang to remove the brownies from the baking dish in one piece. Spread the frosting on the brownies and sprinkle with the toasted coconut. Cut into bars to serve. The brownies can be made up to a day ahead and refrigerated in the baking dish.