Task-optimized control of open quantum systems