A quick way to do this (for core YUI modules) is the YUI Configurator: http://yuilibrary.com/yui/configurator/ -- this will build you two minified rollup files for all the base JS and CSS you need.
The core team is working on a tool called "Grifter" that will do the same thing, but also handle non-core modules.
You may also want to look into using a combo loader, rather than a single JS file. It depends whether you basically need to load the same JS on every page (single file is good), or whether your JS varies a lot from page to page (combo loader is good).