Answer:
Gary and I is the subject of the sentence: Gary and I will pick up the pizza.
Gary and me is the object of the sentence: The teacher told Gary and me to be on time.
You can give this test yourself by taking Gary out of the sentence: "I will pick up the pizza" or "Me will pick up the pizza" and "The teacher told I to be on time" or The teacher told me to be on time".