Minecraft wiki entry for Before_1.8, associated text: Stackable items can be renamed as a stack; you do pay for each item, but the total cost is capped at 39 levels, for which you can rename a full stack.
Note that renamed items in general will not stack with normal items, and renamed blocks lose their name when placed.