In this paper, we study the railcar retrieval problem (RRT) in which specified numbers of certain types of railcars must be withdrawn from the storage tracks of a flat yard. This task arises as part of daily operations of railcar maintenance workshops. The objective is to minimize the total cost of the shunting operations. We describe the RRT formally, present a mixed-integer program formulation and prove the general case to be NP-hard. For some special cases, exact algorithms with polynomial runtimes are proposed. We also analyze several intuitive heuristic solution approaches motivated by current real-world planning routines. We evaluate their average performances in simulations with different scenarios and provide their worst-case perfor...