Brandon Watson has an excellent post on Darwin and teleology:
The most important is that the word ‘teleology’ is ambiguous, and was already ambiguous in Darwin’s time. By ‘teleology’ you can mean Paleyan teleology, in which organisms exhibit a design plan that is explained by the imposition of a designer in a special creation at some point in history. There is no question that Darwin rejects this, and rejects it vehemently. The Origin is in many ways one continual attack on this view.
But ‘teleology’ has another meaning, and certainly another meaning in Darwin’s time. It helps if we go back to Georges Cuvier, the zoologist. Cuvier formulated an approach to zoology based on what he called conditions of existence. As he puts it in his work, The Animal Kingdom:
There is, however, a principle peculiar to Natural History, which it uses with advantage on many occasions; it is that of the conditions of existence, commonly styled final causes. As nothing can exist without the re-union of those conditions which render its existence possible, the component parts of each being must be so arranged as to render possible the whole being, not only with regard to itself but to its surrounding relations. The analysis of these conditions frequently conducts us to general laws, as certain as those that are derived from calculation or experiment.
In other words, from the existence of a thing you can infer, in a general way, the conditions that make its existence possible; in particular, the parts of an animal must act and interact in such a way that the animal can actually exist. As we study how action and interactions make the existence of particular animals possible, however, we begin to see general principles governing these conditions of existence, and this is how we understand both how animals work and how they fit into their environment.