Federated Learning While Providing Model as a Service: Joint Training and Inference Optimization