General theory of controllability and observability of composite systems