Co-design of Safe and Efficient Factory Automation Systems