Preheat the oven to 350°F and grease a 9-inch tart pan with nonstick cooking spray. A springform pan can be used if needed.
In a medium bowl, whisk together the flour, sea salt, baking soda, and baking powder. Set aside.
In the bowl of a stand mixer fitted with the paddle attachment, cream the butter and sugars together on medium speed for about 2 minutes, or until light and fluffy. Scrape down the sides of the bowl as needed.
Add the egg and vanilla extract and mix for about 30 seconds. Gradually add the dry ingredients and mix on low speed until just combined.
If using chocolate chips or chopped chocolate, mix them in now until evenly distributed. Gently fold in the M&Ms with a spatula, reserving a few for the top if desired.
Transfer the dough to the prepared pan and spread it into an even layer using an offset spatula or your hands. Press additional M&Ms onto the surface for decoration, if desired.
Bake for about 15 minutes, or until the edges are lightly golden brown. Allow the cookie cake to cool completely before removing it from the pan.
To make the frosting, combine all frosting ingredients in a mixing bowl and beat with a hand mixer until smooth. Add a small amount of milk if needed to reach your desired piping consistency.
Pipe the frosting around the edges of the cooled cookie cake and decorate with sprinkles, if desired. Slice and serve.