Optimization and Learning in Open Multi-Agent Systems