Stability, dissipativity, and optimal control of discontinuous dynamical systems